开发者

Java Swing: Cannot Edit JComponents in JWindow Extension

I wrote a class that extends JWindow that serves as a kind of customizable dialog box in my application. When I need to invoke one of these windows, I create a new instance of the class; to remove the window, I call the method dispose().

The problem I am having is that the user cannot edit components that have a text box, such as JTextField and JSpinner. The user can click on components such as drop-down boxes and buttons, and this works fine, but when it comes to entering text in a text box, this开发者_StackOverflow does not work.

Has anyone else experienced this problem?

Thanks!


There are a bunch of conditions to meet until a window child can receive focus, see the api doc for window.isFocusableWindow().

for most contexts it's enough to set its focusableWindowState property to true, like

    JFrame owner = new JFrame();
    owner.setVisible(true);
    JWindow window = new JWindow(owner);
    window.setFocusableWindowState(true);
    window.add(new JTextField("edit me"));
    window.setSize(200, 200);
    window.setVisible(true);


1) maybe you are mixing AWT with Swing drop-down box and button, are you sure that all Components definitions starts with J, drop-down boxes == JComboBox, Button == JButton etc

2) don't create lots of Top-Level Containers on the Fly/Runtinme

3) Has anyone else experienced this problem? no, never

4) for real and better help sooner, please edit you post and sent here code that demonstrate your problem here are simples rulles sscce

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜