aspose file tools*
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
Author

JComboBox

Stephanie Johnson
Greenhorn

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: 2213
    
    7


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
Sheriff

Joined: Oct 27, 2005
Posts: 19757
    
  20

Rob Camick wrote:class ItemRenderer extends BasicComboBoxRenderer

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Stephanie Johnson
Greenhorn

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

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: http://aspose.com/file-tools
 
subject: JComboBox