• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JComboBox

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:class ItemRenderer extends BasicComboBoxRenderer


I'd extend DefaultListCellRenderer instead, so it will be less look&feel dependant.
 
Stephanie Johnson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much. I will give these suggestions a try.
 
Stephanie Johnson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic