It's been awhile since I used Swing, and I ran into an issue. I wanted to
have a pulldown text choice widget using a JComboBox with the following
code:
String[] list = {"one", "two", "three"};
JComboBox companyName = new JComboBox(list);
companyName.setEditable(true);
rootPane.add(companyName);
However, the pulldown menu does not appear when the arrow is pressed. What
am I missing?
Thanks.
> It's been awhile since I used Swing, and I ran into an issue. I wanted to
> have a pulldown text choice widget using a JComboBox with the following
[quoted text clipped - 3 lines]
> JComboBox companyName = new JComboBox(list);
> companyName.setEditable(true);
getContentPane().add( companyName );
validate();
> However, the pulldown menu does not appear when the arrow is pressed. What
> am I missing?
Try the above, if that fails, I suggest
you prepare an SSCCE..
<http://www.physci.org/codes/sscce>
HTH
Andrew T.
Paul Hunter - 26 Jan 2007 05:07 GMT
One SSCCE as requested:
import java.awt.*;
import javax.swing.*;
public class test1 extends JFrame {
public test1 () {
super();
setSize(200,200);
Container rootPane = getRootPane();
rootPane.setLayout(new FlowLayout());
String[] list = {"one", "two", "three"};
JComboBox box = new JComboBox(list);
box.setEditable(true);
rootPane.add(box);
}
public static void main (String[] args) {
test1 s = new test1();
s.run();
}
public void run () {
setVisible(true);
}
}
>> It's been awhile since I used Swing, and I ran into an issue. I wanted to
>> have a pulldown text choice widget using a JComboBox with the following
[quoted text clipped - 18 lines]
>
> Andrew T.
Andrew Thompson - 26 Jan 2007 05:33 GMT
> One SSCCE as requested:
Please refrain from top-posting.
I trimmed your SSCCE, here's my version.
<sscce>
import java.awt.*;
import javax.swing.*;
public class test1 extends JFrame {
public test1 () {
super();
setSize(200,200);
setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
// do you recall me mentioning
// 'content pane' earlier?
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
String[] list = {"one", "two", "three"};
JComboBox box = new JComboBox(list);
box.setEditable(true);
contentPane.add(box);
// do you recall me mentioning
// 'validate' earlier?
validate();
}
public static void main (String[] args) {
test1 s = new test1();
s.setVisible(true);
}
}
</sscce>
The drop-down values can be selected in this version.
Andrew T.
Thomas A. Russ - 29 Jan 2007 19:50 GMT
> Container rootPane = getRootPane();
^^^^
Container rootPane = getContentPane();
This is the mistake. You want to add the component to the Frame's
contentPane, not the rootPane.

Signature
Thomas A. Russ, USC/Information Sciences Institute