Questions tagged [jcombobox]

A JComboBox is a Java GUI object. It is a combination of a drop-down list and a single-line JTextField, allowing the user to either type a value directly into the control or choose from the list of existing options.

A JComboBox is a Java GUI object. It is a combination of a drop-down list and a single-line JTextField, allowing the user to either type a value directly into the control or choose from the list of existing options.

2438 questions
169
votes
8 answers

JComboBox Selection Change Listener?

I'm trying to get an event to fire whenever a choice is made from a JComboBox. The problem I'm having is that there is no obvious addSelectionListener() method. I've tried to use actionPerformed(), but it never fires. Short of overriding the model…
Allain Lalonde
  • 91,574
  • 70
  • 187
  • 238
55
votes
2 answers

Why isn't getSelectedItem() on JComboBox generic?

JCombobox in Java 7 has been updated to use generics - I always thought it was a bit of an oversight that it didn't already so I was pleased to see this change. However, when attempting to use JCombobox in this way, I realised that the methods I…
Michael Berry
  • 70,193
  • 21
  • 157
  • 216
39
votes
10 answers

Why is itemStateChanged on JComboBox is called twice when changed?

I'm using a JComboBox with an ItemListener on it. When the value is changed, the itemStateChanged event is called twice. The first call, the ItemEvent is showing the original item selected. On the second time, it is showing the item that has been…
Nicks
  • 1,051
  • 2
  • 11
  • 12
38
votes
4 answers

Populating Swing JComboBox from Enum

I would like to populate a java.swing JComboBox with values from an Enum. e.g. public enum Mood { HAPPY, SAD, AWESOME; } and have these three values populate a readonly JComboBox. Thanks!
mhansen
  • 1,102
  • 1
  • 12
  • 18
34
votes
10 answers

How to set selected index JComboBox by value

I want to set the selected index in a JComboBox by the value not the index. How to do that? Example public class ComboItem { private String value; private String label; public ComboItem(String value, String label) { this.value…
Arto Uusikangas
  • 1,889
  • 5
  • 20
  • 33
28
votes
8 answers

How do I populate a JComboBox with an ArrayList?

I need to populate a JComboBox with an ArrayList. Is there any way to do this?
Abdul Khaliq
  • 2,423
  • 12
  • 40
  • 65
26
votes
3 answers

Dynamically change JComboBox

I am fetching the data values from the database successfully. I have also stored them into a String[] array. I need to load the String array as the items of the JComboBox in response to key actionperformed. How can I reload the items of the…
Suman.hassan95
  • 3,895
  • 8
  • 26
  • 24
22
votes
6 answers

Adding items to a JComboBox

I use a combo box on panel and as I know we can add items with the text only comboBox.addItem('item text'); But some times I need to use some value of the item and item text like in html select: