JComboBox actionPerformed vs itemStateChanged

I have a problem with the selection of the combo box not working on the first selection, but working on subsequent selections.
     cboCondition = new JComboBox();
     cboCondition.setBounds(100, 55, 130, 20);
     cboCondition.addItem("");
     cboCondition.addItem("INTEND TO CLOSE");
     cboCondition.addItem("CLOSED");
     cboCondition.setSelectedIndex(0);
     panel.add(cboCondition);
     void addConditionListener(ActionListener cil){
          cboCondition.addActionListener(cil);
     }Located within the constructor of the top level class containing the class listed below.
c_abView.addConditionListener(new AddConditionListener());
     class AddConditionListener implements ActionListener{
          @Override
          public void actionPerformed(ActionEvent e) {
               final JComboBox cb = (JComboBox)e.getSource();
               SwingUtilities.invokeLater(new Runnable(){
                    @Override
                    public void run() {
                         if(cb.getSelectedItem().equals("")){
                              c_abView.getLblConditionSymbol().setIcon(null);
                              c_abView.getLblDirectionSymbol().setIcon(null);
                              c_abModel.setIntendtoclose(false);
                              c_abModel.setClosed(false);
                         else if(cb.getSelectedItem().equals("INTEND TO CLOSE")){
                              c_abView.getLblConditionSymbol().setIcon(new ImageIcon(AddBarricadesView.class.getResource("/images/intend_to_close.jpg")));
                              c_abView.getLblDirectionSymbol().setIcon(null);
                              c_abModel.setIntendtoclose(true);
                              c_abModel.setClosed(false);
                              c_abModel.updateStatusCode();
                         else if(cb.getSelectedItem().equals("CLOSED")) {
                              c_abView.getLblConditionSymbol().setIcon(null);
                              c_abModel.setIntendtoclose(false);
                              c_abModel.setClosed(true);
                              c_abModel.updateDirectionSymbol();
     } // end AddConditionListenerIn the method updateStatusCode(), I am displaying some information about the code on the form. However, it will only display when the combo box option is clicked a second time, not the first time. What am I missing? Should I be using an itemListener?

I found out that this only happens when I run my application in my IDE (WDSc). When I deploy the jar to my desk top and run it, it works fine.

Similar Messages

  • JComboBox executing multiple itemStateChanged events

    Hello all!
    Can someone plese tell me why this ItemListener executes twice for one change? More importantly how to stop it from doing so?
    private void buildTypeComboBox()
       typeOptions = new JComboBox(types);
       typeOptions.setMaximumRowCount(types.length);
       typeOptions.addItemListener
       (new ItemListener()
              public void itemStateChanged(ItemEvent e)
                fldType = types[typeOptions.getSelectedIndex()];
                if(fldType.equals("VARCHAR"))
                  String input;
                  input = JOptionPane.showInputDialog("Enter the size of this VARCHAR.");
                  varcharSz = Integer.parseInt(input);
    }

    Hi,
    try something like this.
    public void itemStateChanged(ItemEvent ie){
    if(ie.getStateChanged() == ItemEvent.SELECTED){
    // here do whatever you were going to do when the item was selected
    }

  • Editable JComboBox [URGENT]

    Hi All,
    I have an editable JComboBox.It is having some values in the model.By using getSelectedItem() ,i can get the value that was selected.But suppose if the user types a new value which is not there in its model, how to get that value.If i use getSelectedItem(), i am getting a null pointer exception.Can somebody help me?
    Thanks in advance
    Ashok

    Thanx for ur advise.I am getting the value with the method you said and with getSelectedItem() also but it is still throwing NullPointerException.The stack is as follows.
    java.lang.NullPointerException
    at javax.swing.JComboBox.getSelectedIndex(JComboBox.java:479)
    at javax.swing.plaf.basic.BasicComboPopup.syncListSelectionWithComboBoxSelection(BasicComboPopup.java:810)
    at javax.swing.plaf.basic.BasicComboPopup$ItemHandler.itemStateChanged(BasicComboPopup.java:613)
    at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:846)
    at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:891)
    at javax.swing.JComboBox.contentsChanged(JComboBox.java:946)
    at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:79)
    at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:86)
    at javax.swing.JComboBox.actionPerformed(JComboBox.java:925)
    at javax.swing.plaf.basic.BasicComboBoxUI$EditorFocusListener.focusLost(BasicComboBoxUI.java:1402)
    at java.awt.AWTEventMulticaster.focusLost(AWTEventMulticaster.java:171)
    at java.awt.Component.processFocusEvent(Component.java:3644)
    at javax.swing.JComponent.processFocusEvent(JComponent.java:2058)
    at java.awt.Component.processEvent(Component.java:3537)
    at java.awt.Container.processEvent(Container.java:1164)
    at java.awt.Component.dispatchEventImpl(Component.java:2595)
    at java.awt.Container.dispatchEventImpl(Container.java:1213)
    at java.awt.Component.dispatchEvent(Component.java:2499)
    at java.awt.LightweightDispatcher.setFocusRequest(Container.java:2076)
    at java.awt.Container.proxyRequestFocus(Container.java:1335)
    at java.awt.Container.proxyRequestFocus(Container.java:1330)
    at java.awt.Container.proxyRequestFocus(Container.java:1330)
    at java.awt.Container.proxyRequestFocus(Container.java:1330)
    at java.awt.Component.requestFocus(Component.java:4192)
    at javax.swing.JComponent.grabFocus(JComponent.java:967)
    Any idea why so?

  • JComboBox focusLost sets Transaction dirty

    A JComboBox bound to a ViewObject in an ApplicationModule sets that ApplicationModule's transaction dirty even if no changes were made. The combobox list wasn't even opened, just focus in and out or tab-in and tab-out.
    This seems to be a side-effect of having a different column displayed to that bound to the JComboBox.
    This binding works correctly (VcVehicleRegistration is the bound column and the displayed column):
    mVcVehicleRegistration.setModel(JUComboBoxBinding.createLovBinding(panelBinding, mVcVehicleRegistration, "VehicleIncidents", null, "VehicleIncidentsIter", new String[] {"VcVehicleRegistration"}, "VehicleView", new String[] {"VcVehicleRegistration"}, new String[] {"VcVehicleRegistration"}, null, null));
    whereas this fails (VcCauseCode is the bound column, but VcDescription is displayed):
    mVcCauseCode.setModel(JUComboBoxBinding.createLovBinding(panelBinding, mVcCauseCode, "VehicleIncidents", null, "VehicleIncidentsIter", new String[] {"VcCauseCode"}, "CauseView", new String[] {"VcCauseCode"}, new String[] {"VcDescription"}, null, null));
    Tony.

    I'm doing more-or-less what you did.
    I've just reproduced it with a simple panel.
    Panel already exists with 5 attributes from a single ViewOject (which are from a single EntityObject) - PersonnelView.
    This operates fine and tabbing-through has no problems.
    Drop in a ComboBox and bind it to the Branch ViewObject (also single Entity) and display the Branch name:
    jComboBox1.setModel(JUComboBoxBinding.createLovBinding(panelBinding, jComboBox1, "PersonnelView", null, "PersonnelViewIter", new String[] {"VcBranch"}, "BranchView", new String[] {"VcBranch"}, new String[] {"VcBranchName"}, null, null));
    Tabbing out of this field sets transaction dirty.
    How can I check I really am using C:\JDeveloper\BC4J\jlib\FixForBug2632152.jar?
    I can e-mail the relevant SQL, BusinessComponents XML and JClient.java if you like.
    In the mean-time, I've sub-classed JUNavigationBar and dumped the stack when transactionStateChanged() is called (see below).
    Tony.
    java.lang.Exception: Stack trace
         void java.lang.Thread.dumpStack()
              Thread.java:997
         void com.lynx.cc.NavBar.transactionStateChanged(boolean)
              NavBar.java:106
         void oracle.jbo.uicli.binding.JUApplication.setTransactionModified()
              JUApplication.java:860
         void oracle.jbo.uicli.jui.JUPanelBinding.callBeforeSetAttribute(oracle.jbo.uicli.binding.JUControlBinding, oracle.jbo.Row, oracle.jbo.AttributeDef, java.lang.Object)
              JUPanelBinding.java:481
         void oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(oracle.jbo.Row, oracle.jbo.AttributeDef, java.lang.Object, boolean)
              JUCtrlValueBinding.java:466
         void oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(oracle.jbo.Row, oracle.jbo.AttributeDef, java.lang.Object)
              JUCtrlValueBinding.java:422
         void oracle.jbo.uicli.binding.JUCtrlListBinding.setTargetAttrsFromLovRow(oracle.jbo.Row, oracle.jbo.Row)
              JUCtrlListBinding.java:678
         void oracle.jbo.uicli.binding.JUCtrlListBinding.updateTargetFromSelectedValue(java.lang.Object)
              JUCtrlListBinding.java:748
         void oracle.jbo.uicli.jui.JUComboBoxBinding.actionPerformed(java.awt.event.ActionEvent)
              JUComboBoxBinding.java:430
         void javax.swing.JComboBox.fireActionEvent()
              JComboBox.java:870
         void javax.swing.JComboBox.selectedItemChanged()
              JComboBox.java:894
         void javax.swing.JComboBox.contentsChanged(javax.swing.event.ListDataEvent)
              JComboBox.java:950
         void javax.swing.AbstractListModel.fireContentsChanged(java.lang.Object, int, int)
              AbstractListModel.java:79
         void javax.swing.DefaultComboBoxModel.setSelectedItem(java.lang.Object)
              DefaultComboBoxModel.java:86
         void javax.swing.JComboBox.actionPerformed(java.awt.event.ActionEvent)
              JComboBox.java:925
         void javax.swing.plaf.basic.BasicComboBoxUI$EditorFocusListener.focusLost(java.awt.event.FocusEvent)
              BasicComboBoxUI.java:1399
         void java.awt.AWTEventMulticaster.focusLost(java.awt.event.FocusEvent)
              AWTEventMulticaster.java:171
         void java.awt.Component.processFocusEvent(java.awt.event.FocusEvent)
              Component.java:3642
         void javax.swing.JComponent.processFocusEvent(java.awt.event.FocusEvent)
              JComponent.java:1980
         void java.awt.Component.processEvent(java.awt.AWTEvent)
              Component.java:3535
         void java.awt.Container.processEvent(java.awt.AWTEvent)
              Container.java:1164
         void java.awt.Component.dispatchEventImpl(java.awt.AWTEvent)
              Component.java:2593
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1213
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         boolean java.awt.LightweightDispatcher.setFocusRequest(java.awt.Component)
              Container.java:2076
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1335
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Component.requestFocus()
              Component.java:4174
         void javax.swing.JComponent.grabFocus()
              JComponent.java:915
         void javax.swing.DefaultFocusManager.focusNextComponent(java.awt.Component)
              DefaultFocusManager.java:93
         void javax.swing.DefaultFocusManager.processKeyEvent(java.awt.Component, java.awt.event.KeyEvent)
              DefaultFocusManager.java:71
         void javax.swing.JComponent.processKeyEvent(java.awt.event.KeyEvent)
              JComponent.java:2007
         void java.awt.Component.processEvent(java.awt.AWTEvent)
              Component.java:3553
         void java.awt.Container.processEvent(java.awt.AWTEvent)
              Container.java:1164
         void java.awt.Component.dispatchEventImpl(java.awt.AWTEvent)
              Component.java:2593
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1213
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         boolean java.awt.LightweightDispatcher.processKeyEvent(java.awt.event.KeyEvent)
              Container.java:2155
         boolean java.awt.LightweightDispatcher.dispatchEvent(java.awt.AWTEvent)
              Container.java:2135
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1200
         void java.awt.Window.dispatchEventImpl(java.awt.AWTEvent)
              Window.java:926
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         void java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent)
              EventQueue.java:339
         boolean java.awt.EventDispatchThread.pumpOneEventForHierarchy(java.awt.Component)
              EventDispatchThread.java:131
         void java.awt.EventDispatchThread.pumpEventsForHierarchy(java.awt.Conditional, java.awt.Component)
              EventDispatchThread.java:98
         void java.awt.EventDispatchThread.pumpEvents(java.awt.Conditional)
              EventDispatchThread.java:93
         void java.awt.EventDispatchThread.run()
              EventDispatchThread.java:85

  • Toplink with sql server

    I have sucessfully used Toplink with Oracle. ow I have to use it with MS SQL server and I am having problems. First of all, in the Mapping Worbench, the only SQL server driver listed is weblogic.jdbc.mssqlserver4.Driver. Why can't I use the regular ms sql driver, com.microsoft.jdbc.sqlserver.SQLServerDriver? Why should the mapping workbench be tied to Weblogic? If one did not have Weblogic, would it be impossible to use Toplink with SQL server? Well, I have Weblogic, so I tried using the weblogic driver with the url jdbc:microsoft:sqlserver://<host ip>:1433;DatabaseName=<db name>. When I try to connect, a dialog box appears that says: "java.sql.SQLException $$$$$$$$$$ License Exception $$$$$$$$$$ Missing license for: WebLogic Server 6.1. $$$$$$$$$$ License Exception $$$$$$$$$$ Username or password could be invalid." I have weblogic.jar in the classpath. I tried adding the line SET WLS61_HOME=M:\bea610\wlserver6.1 to workbench.cmd. It didn't help. Any suggestions?

    I already tried this. It does not work. I put the following jars in the classpath in workbench.cmd: msbase.jar;mssqlserver.jar;msutil.jar. Then I start workbench. When I try to enter com.microsoft.jdbc.sqlserver.SQLServerDriver as the driver, I get an exception. Here is the stacktrace:
    Exception occurred during event dispatching:
    java.lang.ClassCastException: com.webgain.openapi.foundation.uitools.WGDefaultListModel
         at com.webgain.workbench.ui.db.BldrLoginInfoPanel.actionPerformed(Unknown Source)
         at com.webgain.openapi.foundation.uitools.WGListChooser.fireActionEvent(WGListChooser.java:664)
         at com.webgain.openapi.foundation.uitools.WGListChooser$ListDataHandler.contentsChanged(WGListChooser.java:473)
         at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
         at com.webgain.openapi.foundation.uitools.WGDefaultListModel.setSelectedItem(WGDefaultListModel.java:740)
         at com.webgain.openapi.foundation.uitools.WGListChooser.setSelectedItem(WGListChooser.java:1446)
         at com.webgain.openapi.foundation.plaf.basic.WGBasicListChooserUI$ListChooserModel.setSelectedItem(WGBasicListChooserUI.java:527)
         at javax.swing.JComboBox.actionPerformed(Unknown Source)
         at javax.swing.plaf.basic.BasicComboBoxUI$EditorFocusListener.focusLost(Unknown Source)
         at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
         at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
         at java.awt.Component.processFocusEvent(Unknown Source)
         at javax.swing.JComponent.processFocusEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.setFocusRequest(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Component.requestFocus(Unknown Source)
         at javax.swing.JComponent.grabFocus(Unknown Source)
         at javax.swing.JComponent.requestFocus(Unknown Source)
         at javax.swing.text.DefaultCaret.mousePressed(Unknown Source)
         at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
         at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
         at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at com.webgain.openapi.foundation.uitools.WGPasswordField.processMouseEvent(WGPasswordField.java:99)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    If I ignore the exception and try to connect to the database anyway, it tries to use the weblogic driver.
    Next I manually edited the database xml file and put in the driver name automatically. When I bought up the mapping workbench again, it again threw an exception. However, the correct driver name was in the file, so it did finally let me connect to the database. So it seems there IS a bug, although it has to do with the GUI and not SQL server per se.

  • I want answer of my question below

    question related to SWING - JComboBox :
    why the itemStateChanged(ItemEvent ie) called twice while i am selecting an item that present in the COMBO?

    One item is deselected, and another is selected. The ItemEvent passed contains information about the event type
    Mike

  • How to update Jtable based on itemStateChanged in JComboBox?

    My bad... I originally posted this topic in the Java Programming forum before I found this forum. My apologies.
    Anyway, can someone help me out pls? I need to be able to update my JTable based on the selected item in the combobox. Unfortunately, my JTable doesn't update when I choose another item in the combo box. What am I doing wrong? I've read about TableModels but I'm not quite sure how to use it.
    my code:
    my_constructor()
    JComboBox cbdisease;
    cbdisease = new JComboBox();
    cbdisease.setEditable(false);
    cbdisease.setBounds(30,20,270,25);
    add(cbdisease);
    cbdisease.addActionListener(this);
    cbdisease.addItem("View All");
    //aside from "View All" that was previously added to the combo box
    //get the values from the database to fill the comboBox
    showDiseases();
    cbdisease.addItemListener(new ItemListener()
    public void itemStateChanged(ItemEvent e)
    System.out.println(cbdisease.getSelectedItem());
    displayRules();
    }// end constructor
    method: showDiseases
    connect to DB and get D_Description (column in database)
    display D_Description in combo box
    public void showDiseases()
    Connection conn = null;
    ResultSet rs = null;
    Statement statement = null;
    try {
    // Connect to DB
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:mysql:///dbused",
    "root", "");
    // create a statement, execute query
    statement = conn.createStatement();
    rs = statement.executeQuery("SELECT DISTINCT D_Description FROM disease");
    //place D_Description in combo box
    while(rs.next())
    strDesc = rs.getString("D_Description");
    cbdisease.addItem(strDesc);
    conn.close();
    statement.close();
    } catch (SQLException sqle) {
    sqle.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    }//end catch
    }//end showDiseases()
    method: displayRules
    connect to DB and get the rules depending item selected in the combo box
    display the rules in a table
    public void displayRules()
    Connection conn = null;
    ResultSet rs = null;
    Statement statement = null;
    try {
    // Connect to DB
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:mysql:///dbused",
    "root", "");
    // create a statement, execute query
    statement = conn.createStatement();
    if(cbdisease.getSelectedItem().equals("View All"))
    rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease ORDER BY D_DiseaseCode, D_QuestionCode");
    else //query depends on the item selected in combo box other than "View All"
    rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease WHERE" + " D_Description = '" +cbdisease.getSelectedItem()+ "' ORDER BY D_DiseaseCode, D_QuestionCode");
    // Convert the result set into an array of Objects
    Object[][] rows = getObjects(rs);
    // These are the column headings displayed in the JTable
    String[] headings = { "Disease Code", "Description", "Question Code", "Question", "Action", "# of Arrows", "Arrow"};
    // Initialize a JTable with the rows of objects and column headings
    rulestable = new JTable(rows, headings);
    // Add the table to a JScrollPane to make it display nicely
    rulesScroll = new JScrollPane(rulestable);
    // Add the scroll pane to the container
    add(rulesScroll);
    rulesScroll.setBounds(30,80,720,380);
    conn.close();
    statement.close();
    } catch (SQLException sqle) {
    //sqle.printStackTrace();
    System.out.println(sqle.getSQLState());
    } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
    }//end displayRules()
    method: getObjects
    public Object[][] getObjects(ResultSet rs) throws SQLException
    // Find out how many columns are in the result set
    ResultSetMetaData metaData = rs.getMetaData();
    final int colCount = metaData.getColumnCount();
    ArrayList rows = new ArrayList();
    Object[] row = null;
    while (rs.next()) {
    // for each row in the result set, put every column into a temporary Object array
    row = new Object[colCount];
    for (int a = 0; a < colCount; a++)
    row[a] = rs.getObject(a+1);
    // add the temporary Object array to the array list
    rows.add(row);
    // convert the array list to objects
    return (Object[][])rows.toArray(new Object[0][0]);
    }//end getObjects()

    Just pass the new data to a new TableModel object's
    constructor and then u can use this new table model in
    ur JTable constructor. that woud automatically update
    the table data.
    Cheers!
    Asimsir Asim, do you mean inserting
    DefaultTableModel rulesmodel = new DefaultTableModel(rows, headings);
    to my code?
    public void displayRules()
    Connection conn = null;
    ResultSet rs = null;
    Statement statement = null;
    try {
    // Connect to DB
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:mysql:///dbused",
    "root", "");
    // create a statement, execute query
    statement = conn.createStatement();
    if(cbdisease.getSelectedItem().equals("View All"))
    rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease ORDER BY D_DiseaseCode, D_QuestionCode");
    else //query depends on the item selected in combo box other than "View All"
    rs = statement.executeQuery("SELECT D_DiseaseCode, D_Description, D_QuestionCode, D_Question, D_Action, D_NumArrow, D_Arrow FROM Disease WHERE" + " D_Description = '" +cbdisease.getSelectedItem()+ "' ORDER BY D_DiseaseCode, D_QuestionCode");
    // Convert the result set into an array of Objects
    Object[][] rows = getObjects(rs);
    // These are the column headings displayed in the JTable
    String[] headings = { "Disease Code", "Description", "Question Code", "Question", "Action", "# of Arrows", "Arrow"};
    // Initialize a JTable with the rows of objects and column headings
    rulestable = new JTable(rows, headings);
    // Add the table to a JScrollPane to make it display nicely
    rulesScroll = new JScrollPane(rulestable);
    // Add the scroll pane to the container
    add(rulesScroll);
    rulesScroll.setBounds(30,80,720,380);
    conn.close();
    statement.close();
    DefaultTableModel rulesmodel = new DefaultTableModel(rows, headings); //like this?
    rulestable.setModel(rulesmodel);     
    } catch (SQLException sqle) {
    //sqle.printStackTrace();
    System.out.println(sqle.getSQLState());
    } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
    }//end displayRules()

  • How to fire JComboBox itemStateChanged event manually?

    hello:
    I want to know how to fire JComboBox itemStateChanged event manually.
    thank you
    -Daniel

    Call setSelectedIndex or setSelectedItem.

  • How do I set "JComboBox ItemStateChanged function" to do action only once

    I encounter a serious problem with JComboBox.
    When I use "ItemStateChanged" function,
    I found out it does every action TWICE !!!!!
    I need to use "ItemStateChanged" to decrease numbers by 1,
    since it does action twice, the numbers are decrease by 2 everytime, which is not what I intended.
    Are there anyway I could set "ItemStateChanged" to do the action only once?
    Please help me out

    The ItemEvent has a getStateChange() method that tells you what the state change was, "selected" vs "deselected". What you are seeing is that each item changes state twice, from delected to selected and vice versa. Check the result of this method to filter out the unwanted state changes.
    BTW don't use Choice, its AWT not swing.

  • No itemStateChange occurring for JComboBox

    Hi,
    I have a scenario where the JComboBox I have created received the itemStateChange event DESELECT and SELECT for all but 2 items in the
    combo box. The items in the combo box are all of the same type.
    Why would the combo box receive the these events for some items in
    the combo box, but not all?
    Thanks to anyones help.

    hi,at first: the JComboBox is the Source of the ItemChangeEvent not the destination.
    second:can it be that the Box has some double items ? Make them unique and try again.

  • JComboBox  itemStateChanged gets called twice.

    Hi i have a JComboBox whoes itemStateChanged gets called twice. I have taken a look at other post concerning this topic and non have worked for me . I will greatly appreciate it if someone can help me
    here is the code !!!!!!!!!!
    jComboBox3.addItemListener(new ItemListener(){
    public void itemStateChanged(ItemEvent e) {
    if(e.getStateChange() == e.SELECTED){
    jComboBox3_dosomething(e);
    thanks in advance

    Maybe this thread will answer why it gets called twice:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=257226

  • JComboBox itemStateChanged in 1.3 and 1.4

    When I use 1.3 JDK the itemStateChanged() listener is not activated when i do a cb.setselectedindex(-1).
    However in 1.4 JDK the cb.setselectedindex(-1) statement fires a ItemEvent ??

    and is -1 in 1.4. Show us the 10 line demo program you used to test this statement.
    I've never had a problem.

  • Nested JComboBox itemStateChanged conundrum

    Hey, I'm new to the forums, so don't cuss me out yet.
    I need to have nested ComboBoxes, but am running into some goofy loops that prevent me from doing what I need.
    I have clients who have projects and each project has a description.
    In my dialog, there's a combobox where you select a client. the client combobox has an itemstatechange listener that removes all the items from the project combobox and then loads the projects belonging to the selected client into the project combobox.
    Great. this works. BUT, when I add an itemstatechange listener to the project combobox, to fire a description_field.setText("whatever"), I have huge problems.
    -- When I select a client, the itemStateChangeListener removes all items from the project combobox, which then fires the project itemstateChangeListener, which updates the description field, then the client combo listener adds the first project to the combo, which fires the project listener again, and so on and so forth. It's chaos, and creates a nasty loop and mysql server dumps me for having too many connections.
    Here's some code snippets. I need some suggestions.
    private void projectView_client_comboBoxItemStateChanged(java.awt.event.ItemEvent evt) {                                                            
    DBAccess dbsql = new DBAccess();
    String companyName = (String)projectView_client_comboBox.getSelectedItem();
    int companyid = dbsql.getID("client", "company", companyName);
    String[] data = dbsql.fillComboBox("projectname", "project", "client_id", companyid);
    //q is the DefaultComboBoxModel for the projectComboBox
    //it's "q" because NetBeans won't let me change it to anything with more than one character
    q.removeAllElements();
    for(int r=0; r<data.length; r++){
    q.addElement(data[r]);
    //This GetItButton is the only way I could hack this together. I'd rather have this code in the project_comboBoxItemStateListener.
    private void projectView_getIt_buttonActionPerformed(java.awt.event.ActionEvent evt) {               
    DBAccess dbsql = new DBAccess();
    Object[] selectedItem = new Object[1];
    selectedItem[0] = projectView_projectName_comboBox.getSelectedItem();
    String selectedItemStr = (String)selectedItem[0];
    if(selectedItemStr.equalsIgnoreCase("<none>")) {
    // Do nothing, since no records exist with the projectname of "<None>"
    else if(selectedItemStr.equalsIgnoreCase("<new>")){
    newProject_dialog.setVisible(true);
    else{
    // A valid project has been selected
    String[] projStr = {"projectname"};
    //Finds the project record with the project name of the selectedItem in project_comboBox
    Object[] record = dbsql.findRecord("project", projStr, selectedItem);
    //sets the description field to the third column in the given record (description)
    projectView_description_field.setText((String)record[2]);
    }

    Would you always recommend using ActionListeners for comboboxes?No, it depends on what you are trying to do. That said, for what most are
    generally trying to do with a combobox, ActionListeners are usually the correct
    choice.

  • Get help with JComboBox, itemStateChange

    hi, i get quite complex a problem.
    i have a list containing 2 types of list. one list is the car model and the other is the car type.
    so in one combo box, there will be a list of car model. when one car is selected in this, the other combo box will automatically update all the available car type (e.g. car model is BMW and car type is 318).
    i dont know how to keep the second combo box updated immediately after item of the first combo box changes state.
    some one help me pls

    hi,
    thanks for replying but my problem seems too hard for me.
    i just got another problem.
    i still have the file with a number of JFrames inside and the first, or considered to be the "main" JFrame. Now, when i click a button, a second JFrame after that will pop up but I dont know how to setVisible(false) for the main window using Netbeans. could you please help me do that?
    thanks alot

  • Associate Action with jcombobox item

    Is it possible to associate a particular Action with a jcombobox item (for example using setAction()). When the user selects a particular item of jcombobox, the Action must be triggered.
    regards,
    Nirvan.

    Hi,
    You can associate a particular action with a JComboBox. As per my understanding u can add one action perfrom action to combobox or itemStateChanged action
    if u add action perform action, u need to add the following method to ur logic.
    JComboBox combobox=new JComboBox();
        combobox.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
             JComboBox combo = (JComboBox)evt.getSource();
                if(combo.getSelectedItem().equals("LOCATION")) {
                A a = new A();
                a.show();
            } else if(combo.getSelectedItem().equals("HOUSE")) {
                B b= new B();
                b.show();
            });if action is ItemStateChanged then add the following method.
    combobox.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    and write your logic here which one needs to be triggered when this action performed.
            });Hope this will help to you....
    Thanks & Regards,
    Maadhav..

Maybe you are looking for

  • Is forms 10g Patch set 3 (10.1.2.3)  released?

    Hi All, I checked metalink for information regarding Patch set 3 (10.1.2.3) and could see none. Is this released yet? Thanks Rajesh ALex

  • SWFLoader loded swf and relative path issue

    Hi, Before explaining the problem, let me describe the usecase. I have dashboard flex application hosted on Host1. I have another flex application which acts as plugin to dashboard and is hosted on Host2. I am using proxy to load plugin into dashboar

  • Gridbag layout positions

    Hello, I am creating a gui with various swing objects. I put a grouping of various objects within some panels as to allow for simpler layout. The problem however is spaning a jpanel over 2 rows. basically i want one panel on the left that spans 2 row

  • Batch Date in APO = 01.01.1970

    Hi All, I have a problem with the batch date in APO. It shows as 01.01.1970. This effects dynamic pegging as nothing gets pegged to it as it is too far in the past. There is a date of manufacture etc in R3 on the batch. The Delta report shows no inco

  • Map Failed in XI

    Hi Experts, I am using Message mapping which converts Idoc to EDIFACT message. It was working fine but suddenly today morning , the messages started failing . <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.o