Java 6 JComboBox does not work

Hi All,

My application is using some JComboBoxes to select data. There are 2 frames. The first frame calls the second one. JComboBoxes in the first one work fine but JComboBoxes in the second one do not work, when we click the arrow, it hangs. It works fine with Java 5. The problem happens when I switch to use with Java 6 build 104.

Anyone knows how to fix this problem, please help me.

Thanks so much,

lsen

[440 byte] By [lsena] at [2007-11-26 17:25:29]
# 1
can you post a [url http://homepage1.nifty.com/algafield/sscce.html]SSCCE[/url] that demonstrates the problem?
Jasprea at 2007-7-8 23:53:31 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thanks for your request.

It seems to be complicated if I post the source code (not because of hiding code). I describe briefly here:

JComboBoxes --> JPanel --> JInternalFrame --> JDesktopPane --> JFrame

The arrow points out its parent.

If I change JInternalFrame to JFrame, it works fine.

Thanks for your help.

lsen.

lsena at 2007-7-8 23:53:31 > top of Java-index,Desktop,Core GUI APIs...
# 3
thank you for not reading that link that you were posted! we still cant help you cuz we cant see the code that you are using/running?
Nibura at 2007-7-8 23:53:31 > top of Java-index,Desktop,Core GUI APIs...
# 4
It seems to be complicated if I post the source codeYou weren't asked about your current source code. You were asked to post an SSCCE which demonstrates the problem.
itchyscratchya at 2007-7-8 23:53:31 > top of Java-index,Desktop,Core GUI APIs...
# 5

I have demonstration code of this problem:

import java.awt.Component;

import java.awt.GridBagConstraints;

import java.awt.GridBagLayout;

import java.awt.Insets;

import java.awt.Panel;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

public class Test2 {

private static GridBagConstraints c;

public static void main(String[] args) {

JFrame p = new JFrame();

p.setContentPane(makePanel());

p.pack();

p.setVisible(true);

}

private static Panel makePanel() {

Panel container = new Panel();

container.setLayout(new GridBagLayout());

JButton b1 = new JButton("Button 1");

JButton b2 = new JButton("Button 2");

JComboBox cb = new JComboBox(new String[] { "1", "2", "3" });

addComponent(cb, container, 0, 0, 1, 1);

addComponent(b1, container, 0, 1, 1, 1);

addComponent(b2, container, 0, 2, 1, 1);

return container;

}

private static void addComponent(Component addThis, Panel addToThis, int x, int y, int height, int width) {

if (c == null) {

c = new GridBagConstraints();

c.insets = new Insets(4, 4, 4, 4);

}

c.gridx = x;

c.gridy = y;

c.gridheight = height;

c.gridwidth = width;

addToThis.add(addThis, c);

}

}

The problem I am having is that the combo box does not drop down. However, this occurs for me in Java 5 and Java 6.

korthama at 2007-7-8 23:53:31 > top of Java-index,Desktop,Core GUI APIs...
# 6

interesting, if you don't set the insets it works.

it also works with this changed addComponent:

private static void addComponent(Component addThis, Panel addToThis, int x, int y, int height, int width) {

if (c == null) {

c = new GridBagConstraints();

c.insets = new Insets(4, 4, 4, 4);

}

else

c.insets = new Insets(0,0,0,0);

c.gridx = x;

c.gridy = y;

c.gridheight = height;

c.gridwidth = width;

addToThis.add(addThis, c);

}

Al-Cepia at 2007-7-8 23:53:31 > top of Java-index,Desktop,Core GUI APIs...
# 7
You are mixing AWT and Swing! Don't! Use JPanel instead of Panel and, to be safe, JComponent instead of Component.Message was edited by: sabre150
sabre150a at 2007-7-8 23:53:31 > top of Java-index,Desktop,Core GUI APIs...
# 8
Thank you very much for the replies! Changing Component and Panel to JComponent and JPanel does fix the problem! I'm pretty surprised, cause I've been doing this for a very long time... but thanks again!
korthama at 2007-7-8 23:53:31 > top of Java-index,Desktop,Core GUI APIs...