Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your code seems to be a bit confusing. You say that you want to do different things based on what the user selected in JComboBox, but all that you are adding is the names of only rows where etat_syn is 0.</p> <pre><code> if(Integer.parseInt(res.getString("etat_syn"))==0){ jComboBox3.addItem(res.getString("name")) ; } </code></pre> <p>So in your case, no matter which item you select, the etat_syn value for that item will always be zero.</p> <p>I think (though I am guessing, you need something like below:</p> <pre><code>while(res.next()){ jComboBox3.addItem(res.getString("name")) ; jComboBox3.setActionCommand(res.getString("etat_syn")); } </code></pre> <p>and then in the action listener of <code>jComboBox3</code>, you can do like this:</p> <pre><code> jComboBox3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { String actionCommand = actionEvent.getActionCommand(); if("0".equals(actionCommand)) { //Do this } else { //Do something else. } } }); </code></pre> <p>If you want the processing to be in a action listener of a Button, then you can use a <code>Map</code> to store the values, which can then be used for comparision. Your code will change as below:</p> <pre><code>Map&lt;String, Integer&gt; itemsMap = new HashMap&lt;String, Integer&gt;(); //Declare this as a member of the class. while(res.next()){ String name = res.getString("name"); jComboBox3.addItem() ; int value = Integer.parseInt(res.getString("etat_syn")); itemsMap.put(name, value); } </code></pre> <p>and the action listener of the button will be as below:</p> <pre><code> yourButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { String selectedItem = (String)jComboBox3.getSelectedItem(); int value = itemsMap.get(selectedItem); if(value == 0) { //Do this } else { //Do something else. } } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload