Value « JComboBox « Java Swing Q&A





1. GUI: Changing panels based on value of combo box    stackoverflow.com

I have a question about GUI design, specifically with Java Swing and creating clean separation between presentation and model. It's a bit difficult to describe, but essentially we have lots of reference ...

2. jcombobox not loading values from an array    stackoverflow.com

jComboBox1.setModel(customers);


public class CustomerData {

private static final String JDBC_CONNECTION_URL = "jdbc:mysql://localhost/test";
private static final String DATABASE_USER   = "root";
private static final String DATABASE_PASSWORD = "root";

// query to select customer data
private static final ...

3. Need flexible Java key/value collection class for JComboBox    stackoverflow.com

I have a model class that stores keys and values:

public class KeyValue {

    private Object key;
    private String value;

    KeyValue () {
 ...

4. How to change selected value of a JComboBox    stackoverflow.com

I have to two comboboxes, based on the selection made in the first combobox the selected value of the second box should change. Please find the code snippet below:

secondcombobox.setSelectedItem(firstcombobox.getSelectedItem());

5. how to show integer values in JComboBox?    stackoverflow.com

I would like to know how to set a JComboBox that contain integers values that I could save. Here is the definitions of values:

public class Item 
{
    private String ...

6. JComboBox submit value like HTML select    stackoverflow.com

I have a table with two columns - id and desc. Is it possible to show a list of desc column values to the user in a JComboBox and when the ...

7. linking jcombobox values with jtextfield values    stackoverflow.com

I've created an application in netbeans IDE 6.9 where I need to set values for each value in the jcombobox. In my pane I've a combobox and below that are the ...

8. how to modify the values of other fields in JDialog box based on the value in combo box    stackoverflow.com

I am making a dialog box for the application.And I want to fetch the values from the other fields(such as textField) based on the value of combo box. Can anyone please ...

9. How to use a switch to assign value to a selected item from a JComboBox    stackoverflow.com

Here is my problem: In our term there are two java courses. we have been learning about GUI elements. In our latest assignment, we have to register an attendees name. the ...





10. A JComboBox seems to return null value while the selected item isn't null    stackoverflow.com

Here is my problem. I created a JForm which should help to insert new objects "Analyse" in a database, and those "Analyse" objects requires a "Lot" object id to be created. So ...

11. Clearing Last Selected Value JCombobox when ComboBoxModel Becomes Empty    stackoverflow.com

Here is a scenario: I have two JComboBoxes (call them combo1 and combo2 ) that get their values from a database[In the DB, these two have a 1:M relationship]. When the screen ...

12. JComboBox setting label and value    stackoverflow.com

Is it possible to set a value and a label to a JComboBox so I can show a label but get a value that is different? For example in JavaScript I can ...

13. Obtaining value from combo-box in netbeans GUI    stackoverflow.com

Basically I've been experimenting with the use of drop-boxes in a GUI I'm making in netbeans. I know how easy it is to obtain a string variable from a text field ...

14. getting values in to a text area after selecting the combo box    stackoverflow.com

after selecting an item in the combo box particular resultset should be display in a text area. that mean have area codes in the combo box after selecting an area code ...

15. how to compute the result of two integer values but get the additive or multiplicative operator from a jComboBox in java    stackoverflow.com

assume i have integer variables a,b and c.

c = a + b; or c = a - b; or c = a / b; or c = a * b;
As ...

16. Help in automatically changing value upon ItemChange in JComboBox    stackoverflow.com

I have a program in which I am using 3 things, a checkbox, a combobox and a textfield. The logic works like this if checkbox is enable then combobox and textfield ...





17. JComboBoX - Display value(Rulename, Description)    stackoverflow.com

I have 2 Values in my table RuleName and Description and I need to display the both values in ComboBox with wider. But passing parameter should be only the Rule Name. ...

18. Checking whether a JComboBox has the default value or not    stackoverflow.com

EDIT: Since the term "default value" is confusing, I changed it to "initial value." This is sort of an interesting question. I searched on the site for an answer, but didn't find ...

19. How to set selected index jcombobox by value    stackoverflow.com

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;
  ...

20. Changing the value of a JComboBox in Java    stackoverflow.com

I'm trying to change the value of a JComboBox, from an ActionListener, and having no luck. I have a JComboBox that when changed changes the CardLayout (switched to another GUI). I have a ...

21. How to set a JComboBox default value    forums.netbeans.org

I am using Netbeans IDE. My application is a desktop java application. I have a combo box. To fill the box I used the custom code feature and entered the following ...

22. How to get swing.JComboBox bind to database return value with custom code    forums.netbeans.org

I set the custom code to this: cbLeader.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof Leader) { Leader mec = (Leader)value; setText(mec.getScreenname()); } return this; } }); I tried getting the value from the combo box using cbLeader.getSelectedItem().toString() it returns a reference to the ...

23. How to get value from combo box and radio button?    coderanch.com

you can call e.getSource on the event, and that will return of your button. Radio buttons are each a different button. So in your actionPerformed method of your listener you can put: JButton buttonPushed = (JButton) e.getSource(); if (buttonPushed.getName().equals( "blah" )) doBlahStuff; etc. Instead of using getName, you could also use getText, in case you have two buttons with the same ...

24. deselected value from JComboBox    coderanch.com

27. Retaining JCombo values    coderanch.com

I want to retain the combo box values. My requirement is something like this. As soon as the application starts, user cliks an icon, a combo box appears, user selects a value from the drop down, whenever the user clicks the icon and combo box appears, the same value should be retained. Thanks Cosmos

29. Same value in JComboBox    coderanch.com

it sounds like you are adding the items e.g "Store Kraft Mfg" as a String, then using getSelectedIndex() for the index of a data structure. This will always return the first occurence of "Store Kraft Mfg". you need to add the object to the combobox, and use getSelectedItem(). Add a toString() method to the object. toString() will return eg "Store Kraft ...

30. passing value from jcombobox to other classes?    coderanch.com

Hi I have an Jcombobox with an actionlistener set up in a class called "boxSelected", so that when the user clicks on the choice they're after the result is sent to a jtext area. public class boxlistener implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource()==queryBox){ int selectedIndex = queryBox.getSelectedIndex(); String boxSelected = queryBox.getSelectedItem().toString(); System.out.println("Selected: "+boxSelected); String newline = "\n"; textArea.append(boxSelected ...

32. reseting combo box values    coderanch.com

Hi all, I have 2 frames call win1 and win2. Win1 has a button to call win2 that has some JComboBox that represents dates. yearComboBox = new JComboBox(); monthComboBox = new JComboBox(); dayComboBox = new JComboBox(); for (int i=currentYear; i < yearsLater; i++) { yearComboBox.addItem(i); } for (int i=0; i < 12; i++) { String monthStr = DateUtil.getMonthName(i); // change 0 ...

33. JComboBox loading values from db problem    coderanch.com

Hi all. I have 4 JComboBoxes which gets populated depending upon each other. Every thing goes fine until i try to browse i.e go through the values of the ComboBox with the keyboard. It works good with the mouse. I get this error java.sql.SQLException: Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor ...

34. Loading Values into JComboBox, depending on selection from another JComboBox    coderanch.com

To implement the example scenario, you need to add the ActionListner on you Country ComboBox and handle the event within this listener. For example, whenever user chooses any country, query your DB to get the cities for the selected country and update the model of the cities combo box so that the City ComboBox will display the updated data. Refer to ...

35. Display value and Actual value in JComboBox    coderanch.com

If I understand the question then try this: import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.plaf.basic.*; public class ComboBoxItem extends JFrame implements ActionListener { public ComboBoxItem() { Vector model = new Vector(); model.addElement( new Item(1, "car" ) ); model.addElement( new Item(2, "plane" ) ); model.addElement( new Item(3, "train" ) ); model.addElement( new Item(4, "boat" ) ); JComboBox comboBox; // ...

36. getting jcombobox mouse over value    coderanch.com

I'm not clear on what you want. Your topic subject seems to indicate that you want to get the value when you move your mouse of the combo box (which doesn't make sense to me), but your post seems to indicate that you want to get the value when the user selects one from the drop-down. Can you please be more ...

37. how to change the selected value in the jComboBox ,when selecting another jcombobox having same name    coderanch.com

hi guys. i have a jtable and iam using a jComboBox in one column in all rows (all jComboBoxes names are same), I select one Jcombobox ,and select one value from it,and after that when i click on another cell having Jcombobox, it already selects the previous selected value. so, is there any way i can make the value in cell ...

38. How to set ID and Value for a JCombobox    coderanch.com

import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.plaf.basic.*; public class ComboBoxItem extends JFrame implements ActionListener { public ComboBoxItem() { Vector model = new Vector(); model.addElement( new Item(1, "car" ) ); model.addElement( new Item(2, "plane" ) ); model.addElement( new Item(3, "train" ) ); model.addElement( new Item(4, "boat" ) ); model.addElement( new Item(5, "boat aadf asfsdf a asd asd" ) ); ...

39. I want to limit selectable values in Combobox    coderanch.com

I have a simple combobox with two columns CoreNum | UsedFlag I want all values to be displayed. However, if the Usedflag value is 0, I want to prevent it from being selectable, but still display (i.e.grayed out). Snippet: JComboBox jCoreCombo = new JComboBox(); jCoreCombo.setRenderer( new coreRenderer(5) ); class coreRenderer extends JTextArea implements ListCellRenderer { public coreRenderer(int tabSize) { setTabSize(tabSize); } ...

40. getting latest value from combobox    coderanch.com

Hi All, I have an example in which there is a JComboBox in one of the columns of a JTable. This combo box can have only values - X,Y or Z. However, when I try to prepopulate the table, I pass a wrong value "A" to the combo box column. This column has an associated editor and renderer. And as per ...

41. want default value in ComboBox from DB!!    java-forums.org

Hi Friends, Code of my project is in Swing. I want a default value in combobox which is retreiving data from DB.How can I do that? Below in the sample code from the proj. dataLastOne.setName( "dataLastOne" ); add( dataLastOne ); dataLastOne.setCaption( "dataLastOne" ); dataLastOne.setConnectionTimeout( 15 ); dataLastOne.setCommandTimeout( 30 ); dataLastOne.setCursorType( AdoConst.adOpenForwardOnly ); dataLastOne.setLockType( AdoConst.adLockOptimistic ); dataLastOne.setCommandType( AdoConst.adCmdText ); dataLastOne.setMaxRecords( 0 ); ...

43. Get value of JComboBox text field    java-forums.org

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class template { JComboBox comboBox; JFrame frame; template() { String items[] = {"Item1", "Item2", "Item3"}; comboBox = new JComboBox(items); comboBox.setEditable(true); frame = new Frame("Template"); comboBox.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent keyEvent) { System.out.println("A key was pressed"); String comboboxText = (String)comboBox.getSelectedItem(); System.out.println("The string " + comboboxText + "was entered."); } }); frame.add(comboBox); frame.setSize(200, 200); frame.setVisible(true); ...

45. how to set a value from a Combobox after Clicking Ok button    java-forums.org

Hi Everybody. I am trying to make a GUI its have 4 combobox and each combobox have different string values. I am trying to create a Button("OK"). I need to pick some value from each combobox and then click ok button to make changes and exit. And also If I click cancel no changes. Please let me know to performed this ...

46. Change value of combobox value    java-forums.org

I am extremely new to programming and am having a really hard time with what I believe to be a very basic function. I have a combobox with defined values, however, I want the respective selection to pass through different values to specified variables. How do I do this? Here is the code for my combobox Java Code: jComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] ...

47. insert values from database to JComboBox    forums.oracle.com

48. blank values for editable JComboBox    forums.oracle.com

Hello, I have a editable JComboBox that the user can erase its current value and if they simple change focus (like click on a text field on the same panel) the combo box is left blank. i would like to have it so that if the user leaves focus of the box and its blank that current value goes back to ...

49. changing Jcombobox values    forums.oracle.com

50. passing value from jcombobox to other classes?    forums.oracle.com

Hey thanks a lot for your quick reply. I hate to say it though; I'm afraid I haven't got much of an idea what a lot of that meant. Would it be bold of me to ask to have it spelt out to me a bit further? At the moment I'm using tutorials but I'm not finding a lot of these ...

51. Changing value in JcomboBox    forums.oracle.com

52. set value to calendar month class by jcombobox    forums.oracle.com

If you don't want the selected index, don't use getSelectedIndex() (doh!). It looks like you monthArr contains Strings. It should contain the Calendar.JANUARY, etc constants. Then you can use getSelectedItem() to get the selected one (cast to Integer). Then add a renderer to display the actual names for the month constants (using DateFormatSymbols#getMonths() for example).

53. Repainting panel when JComboBox value is changed    forums.oracle.com

What I want to achieve here is to calculate and show l1 new value right then, when a user picks new JComboButton value. For example new JComboButton value is "< 40W || 7W >" and slider value is 100. JLabel l1 new value should be then 100 * 40. At the moment I can't see that change before I have manually ...

54. how to write the value of JComboBox    forums.oracle.com

Thanks for the useful link but what i need is how to write the JComboBox when it is appear in the line i.e if i have the following line Name Hana Age JComboBox Major JComboBox and i need to save all this line in a text file JLabel JTextfiled JLabel JComboBox JLabel JComboBox

56. Question about refreshing values in JComboBox    forums.oracle.com

i have a JComboBox that points to a static array of Objects. I am adding an element to this array at some point, but when i do the JComboBox goes blank! All the entries are blank. If I click inside the blank box it will eventually refresh, but it's really annoying. What can i do to make this addition of an ...