开发者

Invisible JComboBox

I have a little problem. I had some JComboBox to a JDialog but they won't show up ... Moreover I can select them (see the pic).

alt text http://grab.by/3RwI

And here's my code :

for(int i = 0; i<11; 开发者_开发问答i++)
    {
        JComboBox jC = new JComboBox(posteList);
        jC.setBounds(300, posY, 100, 20);
        jC.setSelectedIndex(0);
        this.add(jC);
        posY += 30;
    }

Have you got an idea to solve this problem ? Thanks !


You're not supposed to call setBounds(), you need to use a layout to manage the components positions


I've found a solution for the problem. If you're using a JPanel for the GlassPane, over the glass pane you're using a JInternalFrame. If you try to draw a JFileChooser or JCombobox, sometimes the popups don't roll down(I mean it rolls down but rolls under the JPanel). Here is the bugreport from Oracle: When my colleague found this bug report my eyes shined up. So I implemented the solution of the bugreport to a JFrame, then the popups worked fine. The steps are as follows:

  1. First you need to create a JFrame.
  2. Implement the fix(hack) from the bugreport.
  3. You have to add the JPanel(GlassPane) to the JFrames rootPane, like: frame.getRootPane().setGlassPane(panel);
  4. When you add the JComboBox set up this: comboBox.setLightWeightPopupEnabled(true)

I hope this is the fix for your problems too. It worked for me.


Call the doLayout() method of your JComboBox after manually setting the bounds. Then the combo box will appear correctly. E.g.:

JPanel panel = new JPanel();
panel.setLayout(null);

String[] items = {"hello","goodbye","etc"};
JComboBox cbox = new JComboBox(items);
panel.add(cbox);
cbox.setBounds(0, 0, 100, 20);
cbox.doLayout(); // force the JComboBox internals to use your bounds
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜