File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox" Watch "JComboBox" New topic


Stephanie Johnson

Joined: Jun 03, 2009
Posts: 8
I have a JComboBox defined as below. I have a custom class LabelAndValue which has simple get/set for label and value variables. I have also implemented toString method in my custom LabelAndValue class.

JComboBox testType = new JComboBox(new Object[] {
new LabelAndValue("label1", "Value1"),
new LabelAndValue("lable2", "Value2"),

User will be able to see lable1, lable2 on the screen and I will use value1, value2 to process the selection. I dont have any renderers or action listeners for my combo box. My combo box displays the options only when I keep my mouse pressed. If I just click on the combobox, it displays the drop down and disappears. How do I fix this? Any help is much appreciated.

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2451

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

Rob Camick wrote:class ItemRenderer extends BasicComboBoxRenderer

I'd extend DefaultListCellRenderer instead, so it will be less look&feel dependant.

How To Ask Questions How To Answer Questions
Stephanie Johnson

Joined: Jun 03, 2009
Posts: 8
Thank you so much. I will give these suggestions a try.
Stephanie Johnson

Joined: Jun 03, 2009
Posts: 8
This works fine when I run my code from Windows. When I launch the same program from Linux and make the display come through X windows client, combobox dropdown doesnt work. Also, I am unable to resize any of JSplitPanes in X windows display.
I agree. Here's the link:
subject: JComboBox
It's not a secret anymore!