Event problem in editable combo box

I have three editable combo box in my JDialog. I can select the value from the combo or I can enter any value. I have to perform some operation when one button is pressed after I have given the values in the three combo boxes. Here, If I select any value from the combo box, there is no problem. But if I enter the value in the combo boxes, when I press the button, in the first click nothing is happening. The First click just selects the value that entered in the last combo box and in the second click it works properly. I am not facing this problem in JDK 1.2.2 or JDK1.3. This occurs only in JDK1.4. Please let me if anyone knows the reason for this.
Thanks.

in the fla that contains your loadMovie() statement:
1. drag a combobox to the stage.
2. remove it.
3. the combobox component will now be in your library.
re-publish your swf and retest.

Similar Messages

  • Problems in editable Combo Box

    Hello,
    I have an editable Combo Box and an action listener associated with the Combo Box. I also have a "Store" button that stores the edited item in the Combo Box and an action listener associated with the button too. After I have selected an item in the Combo Box and edited it, I press the "Store Button". Instead of going to the Store_button_action performed method, it goes to the ComboBox_action performed method and after running it, it stops. Which means it does not run the Store_button_action performed method at all.
    Another thing I have noticed is that when ever I select any item from this Combo Box it gets highlighted in blue, is there some way around this? I want the cursor to be blinking at the beginning/end of the selected Item.
    Thanks and regards,
    Ibha

    Hi,
    you can use a Textfield as editor component for a ComboBox:
    create a class implementing javax.swing.ComboBoxEditor with an attribute type Textfield. This TextField uses your PlainDocument.
    In getEditorComponent() you return the TextField.
    Hope this helps,
    Phil

  • Problem with editable combo box and creating dynamic table values using js

    Hai
    I have used jquery.jec.js to make my dropdown list as editable... I need to create dynamic table values on the onChange event of dropdown using javascript.
    Now am facing the problem in it...
    I am getting duplicate rows in the table... think(assumption) this jquery.jec.js is calling the dropdown again creating duplicate values...
    Please help me out.... Any help is appreciable... Thanks in advance

    Thanks elOpalo, for your valuable response....
    I have found the correct way of doing.
    Before i had my code like this,
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>test</title>
    <script type="text/javascript" src="js/jquery-latest.js"></script>
    <script type="text/javascript" src="js/jquery.jec.js"></script>
    <script type="text/javascript">
    $(function(){
    $('#list').jec();
    function giveAlert(){
         alert('hello');
    </script>
    </head>
    <body>
    <form>
    Combo Box:
    <select id="list" name="list" onChange="giveAlert();">
    <option value="1">one</option>
    <option value="2">two</option>
    </select>
    </form>
    </body>
    </html>
    Now i have changed as the following,
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>test</title>
    <script type="text/javascript" src="js/jquery-latest.js"></script>
    <script type="text/javascript" src="js/jquery.jec.js"></script>
    <script type="text/javascript">
    $(function(){
    $('select.combo').jec();
    $('select.combo')
    .change(function() {
    alert($(this).val());
    }).change();
    </script>
    </head>
    <body>
    <form>
    <table>
    <tr>
    <td>Combo Box:</td>
    <td><select class="combo"><option value="b">banana</option><option value="a">apple</option></select></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    The problem is with the function i have called on the onChange Event.. Now i have defined it inside the jquery function of dropdown to make it as editable...

  • Editable combo box - changing list

    hey all,
    I have to capture a code, which may be one of many types, and have planned on using an editable combo box, which narrows down the available options as the user types into it - as many programs use.
    Problem is that I'm not sure what it is I need to do to make this work. So far I've got my own ComboBoxModel implementation, and I had tried listening to edit changes, and changing the list based on that. Problem is I cant mutate in the middle of the notification, so no luck there.
    Anyone have any ideas how to make this work?
    cheers
    dim

    ttarola:
    I'm not sure if I've misinterpreted your advice, but I couldn't get it to work... here's what I've done:
    public class TestKeyListener extends KeyAdapter
      private int lastItemIndex = -2;
      private final JComboBox comboBox;
      public TestKeyListener(JComboBox comboBox)
        this.comboBox = comboBox;
       * Invoked when a key has been released.
       * As you are typeing in this field it tries to help you to coomplete the
       * expression you are looking for.
      public void keyReleased(KeyEvent e)
        int keyCode = e.getKeyCode();
        JTextField editBox = (JTextField) comboBox.getEditor().getEditorComponent();
        String typedText = editBox.getText();
        int typedTextLength = typedText.length();
        // nothing has been written
        if (typedTextLength == 0)
          comboBox.setSelectedItem("");
          return;
        boolean isDelete = ((keyCode == e.VK_DELETE) || (keyCode == e.VK_BACK_SPACE));
        if (isDelete || (e.getKeyText(keyCode).length() == 1))
          String item;
          for (int i = 0; i < comboBox.getItemCount(); i++)
            item = comboBox.getItemAt(i).toString();
            if (item.startsWith(typedText))
              // after deleting the same item is the actual one
              if (isDelete && lastItemIndex == i)
                return;
              lastItemIndex = i;
              comboBox.setSelectedIndex(lastItemIndex);
              editBox.setText(item);
              editBox.setCaretPosition(typedTextLength);
              editBox.select(typedTextLength, item.length());
              return;
      public static void main(String[] args)
        final JFrame frame = new JFrame("test2");
        frame.addWindowListener(new WindowAdapter()
          public void windowClosing(WindowEvent ev)
            frame.dispose();
            System.exit(0);
        JComboBox comboBox = new JComboBox();
        for (int j = 0; j < 50; j++)
          if (j % 10 == 0) comboBox.addItem("A" + j / 10 + "77" + j);
          if (j % 10 == 1) comboBox.addItem("B" + j / 10 + "77" + j);
          if (j % 10 == 2) comboBox.addItem("C" + j / 10 + "77" + j);
          if (j % 10 == 3) comboBox.addItem("D" + j / 10 + "77" + j);
          if (j % 10 == 4) comboBox.addItem("E" + j / 10 + "77" + j);
        comboBox.setEditable(true);
        comboBox.addKeyListener(new TestKeyListener(comboBox));
        frame.setBounds(1, 1, 500, 300);
        frame.getContentPane().setLayout(new FlowLayout());
        frame.getContentPane().add(comboBox);
        frame.setVisible(true);
    }this doesn't really bother me, as the other poster has solved my problem (see next post)...
    cheers
    dim
    cheers
    dim

  • Editable Combo box in a JTable

    Hi,
    Is it possible to have an editable combo Box in a JTable with an item Listener attached to the combo Box?
    Based on whatever value the user enters in that column that is rendered as a combo Box(editable) i should be able to do some validation. Is this possible?
    Thanks in advance for your time and patience.
    Archana

    Here's a start:
    public class FileModel5 extends AbstractTableModel
    public boolean isEditable = false;
    protected static int NUM_COLUMNS = 3;
    // initialize number of rows to start out with ...
    protected static int START_NUM_ROWS = 0;
    protected int nextEmptyRow = 0;
    protected int numRows = 0;
    static final public String file = "File";
    static final public String mailName = "Mail Id";
    static final public String postName = "Post Office Id";
    static final public String columnNames[] = {"File", "Mail Id", "Post Office Id"};
    // List of data
    protected Vector data = null;
    public FileModel5()
    data = new Vector();
    public boolean isCellEditable(int rowIndex, int columnIndex)
    // The 2nd & 3rd column or Value field is editable
    if(isEditable)
    if(columnIndex > 0)
    return true;
    return false;
    * JTable uses this method to determine the default renderer/
    * editor for each cell. If we didn't implement this method,
    * then the last column would contain text ("true"/"false"),
    * rather than a check box.
    public Class getColumnClass(int c)
    return getValueAt(0, c).getClass();
    * Retrieves number of columns
    public synchronized int getColumnCount()
    return NUM_COLUMNS;
    * Get a column name
    public String getColumnName(int col)
    return columnNames[col];
    * Retrieves number of records
    public synchronized int getRowCount()
    if (numRows < START_NUM_ROWS)
    return START_NUM_ROWS;
    else
    return numRows;
    * Returns cell information of a record at location row,column
    public synchronized Object getValueAt(int row, int column)
    try
    FileRecord5 p = (FileRecord5)data.elementAt(row);
    switch (column)
    case 0:
    return (String)p.file;
    case 1:
    return (String)p.mailName;
    case 2:
    return (String)p.postName;
    catch (Exception e)
    return "";
    public void setValueAt(Object aValue, int row, int column)
    FileRecord5 arow = (FileRecord5)data.elementAt(row);
    arow.setElementAt((String)aValue, column);
    fireTableCellUpdated(row, column);
    * Returns information of an entire record at location row
    public synchronized FileRecord5 getRecordAt(int row) throws Exception
    try
    return (FileRecord5)data.elementAt(row);
    catch (Exception e)
    throw new Exception("Record not found");
    * Used to add or update a record
    * @param tableRecord
    public synchronized void updateRecord(FileRecord5 tableRecord)
    String file = tableRecord.file;
    FileRecord5 p = null;
    int index = -1;
    boolean found = false;
    boolean addedRow = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord5)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    { //update
    data.setElementAt(tableRecord, index);
    else
    if (numRows <= nextEmptyRow)
    //add a row
    numRows++;
    addedRow = true;
    index = nextEmptyRow;
    data.addElement(tableRecord);
    //Notify listeners that the data changed.
    if (addedRow)
    nextEmptyRow++;
    fireTableRowsInserted(index, index);
    else
    fireTableRowsUpdated(index, index);
    * Used to delete a record
    public synchronized void deleteRecord(String file)
    FileRecord5 p = null;
    int index = -1;
    boolean found = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord5)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    data.removeElementAt(i);
    nextEmptyRow--;
    numRows--;
    fireTableRowsDeleted(START_NUM_ROWS, numRows);
    * Clears all records
    public synchronized void clear()
    int oldNumRows = numRows;
    numRows = START_NUM_ROWS;
    data.removeAllElements();
    nextEmptyRow = 0;
    if (oldNumRows > START_NUM_ROWS)
    fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);
    fireTableRowsUpdated(0, START_NUM_ROWS - 1);
    * Loads the values into the combo box within the table for mail id
    public void setUpMailColumn(JTable mapTable, ArrayList mailList)
    TableColumn col = mapTable.getColumnModel().getColumn(1);
    javax.swing.JComboBox comboMail = new javax.swing.JComboBox();
    int s = mailList.size();
    for(int i=0; i<s; i++)
    comboMail.addItem(mailList.get(i));
    col.setCellEditor(new DefaultCellEditor(comboMail));
    //Set up tool tips.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for mail Id list");
    col.setCellRenderer(renderer);
    //Set up tool tip for the mailName column header.
    TableCellRenderer headerRenderer = col.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the Mail Id to see a list of choices");
    * Loads the values into the combo box within the table for post office id
    public void setUpPostColumn(JTable mapTable, ArrayList postList)
    TableColumn col = mapTable.getColumnModel().getColumn(2);
    javax.swing.JComboBox combo = new javax.swing.JComboBox();
    int s = postList.size();
    for(int i=0; i<s; i++)
    combo.addItem(postList.get(i));
    col.setCellEditor(new DefaultCellEditor(combo));
    //Set up tool tips.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for post office Id list");
    col.setCellRenderer(renderer);
    //Set up tool tip for the mailName column header.
    TableCellRenderer headerRenderer = col.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the Post Office Id to see a list of choices");
    }

  • Editable combo box

    I have copied the code for editable combo box. This includes "samples" package. Could anyone guide me where i can get the package in java.sun.com. I am new to java and trying to design a form with editable combo box. Obviously im getting the error "package samples.accessory does not exist". I have searched for accessory class but failed.
    Thanks in advance.

    Or, if the OP doesn't have access to your C drive, from here:I'm glad somebody knows what I'm talking about. :-)

  • SUD Dialog - Vorgabewerte in einer Edit/Combo-Box - Anzeigen von Werten die in einem vorgehendem Durchlauf eingeben wurden

    Ziel ist es in einem SUD Dialog Vorgabewerte in einer Edit/Combo-Box anzeigen zu lassen, um diese Daten nicht bei jedem Aufruf der Autosequenz neu eingeben zu müssen. Sie sollen aber nicht in einer List-Box ausgewählt werden, sondern in einer Edit/combo-Box. Als Vorgabewerte sollten die zuletzt bei einem Durchlauf der Autosequenz eingegebenen Werte oder Texte in dem Fenster der Box erscheinen. Könnte man hier Variablen verwenden? Müssen diese in dem static Fenster eingegeben werden, bzw. mit welcher Befehlszeile?
    Sub EditBox5_EventInitialize()
    Dim This : Set This = EditBox5
    End Sub
    Wir verwenden noch DIAdem 8.0

    Hallo Herr Gutknecht,
    Sie koennen eine DIAdem VAS-Variable von Typ "A" oder "G" benutzen und diese der Combobox als zugehoerige Variable zuweisen. Die moeglichen Werte der "A" oder "G" Variable bleiben von SUD-Start zu SUD-Start in DIAdem erhalten, sowie auch der zuletzt-gewaehlte Wert der Variable. Beim naechsten SUD-Start wird dieser zuletz-gewaehlte Wert in der Combobox dargestellt.
    Mit schoenen Gruessen,
    Brad Turpin
    DIAdem Product Support Engineer (USA)
    National Instruments

  • Action event automatically triggered for combo box

    Hi all,
    I am facing a typical event handling problem for combo box in Swing(Using Net Beans 5.0, jdk 1.4.2)
    While adding items to combo box it is firing action event twice instead of once irrespective of no. of items added to it.
    For eg if there are 1 or more than 1 item added to combo box it is triggerring action event twice(one just after when first item is added and one again when rest all items are added)
    and if there is no item then also it is triggering once.
    Can you please help me out.
    Thanks

    post the SSCCE code, then only it is easy to find the problem

  • Problems with a combo box in dynpro

    Hi guys, im creating a combo box in a dynpro, but is not showing anything.
    the code is the following:
    AT the screen painter..
    MODULE USER_COMMAND_0100.
       PROCESS ON VALUE-REQUEST.
      FIELD TI_COMBO MODULE create_dropdown_box.
    *then the module in the main program.....
    module create_dropdown_box input.
    TYPES: BEGIN OF type_carrid,
             op1(20),
             ID TYPE N,
           END OF type_carrid.
    DATA ti_combo TYPE STANDARD TABLE OF type_carrid WITH HEADER LINE.
    ti_combo-op1 = 'Not processed'.
    TI_COMBO-ID = 1.
    append ti_combo.
    ti_combo-op1 = 'Duplicated.
    append ti_combo.
    ti_combo-op1 = 'For Payroll'.
    append ti_combo.
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
           EXPORTING
            RETFIELD = 'ID'
            DYNPPROG = SY-REPID
            DYNPNR = '100'
            DYNPROFIELD = 'TI_COMBO'
            VALUE_ORG = 'S'
           TABLES
                value_tab       = ti_combo
           EXCEPTIONS
                parameter_error = 1
                no_values_found = 2
                OTHERS          = 3.
      IF sy-subrc <> 0.
      ENDIF.
    endmodule.
    Edited by: javier  santana on May 7, 2008 5:47 PM

    Hi,
    Check the below code.
    TYPE-POOLS: VRM.
    DATA:V_NUM TYPE I.
    DATA:NAME TYPE VRM_ID,
         LIST TYPE VRM_VALUES,
         VALUE LIKE LINE OF LIST.
    DATA:I_WORKPATTERN LIKE ZWORKPAT OCCURS 0 WITH HEADER LINE.
    DATA:ZPATTXT(60).
    MODULE WORKPATTERN_LISTBOX OUTPUT.
    NAME = 'P9434-ZWORKPATTERN'.
        IF V_NUM IS INITIAL.
        CLEAR I_WORKPATTERN.
        REFRESH I_WORKPATTERN.
        SELECT *
               FROM ZWORKPAT
               INTO TABLE I_WORKPATTERN.
        IF NOT I_WORKPATTERN[] IS INITIAL.
          LOOP AT I_WORKPATTERN.
            VALUE-KEY = I_WORKPATTERN-ZWORKPATTERN.
            VALUE-TEXT = I_WORKPATTERN-ZWORKPATTERN.
            APPEND VALUE TO LIST.
          ENDLOOP.
        ENDIF.
        CALL FUNCTION 'VRM_SET_VALUES'
          EXPORTING
            ID                    = NAME
            VALUES                = LIST
         EXCEPTIONS
           ID_ILLEGAL_NAME       = 1
           OTHERS                = 2.
        IF SY-SUBRC <> 0.
          CLEAR SY-SUBRC.
        ENDIF.
        V_NUM = V_NUM + 1.
        ENDIF.

  • Problem rendering a combo box in the data grid

    Hi,
    I am rendering a combo box in the data grid control using an
    item renderer. When I click on it to select a value from the drop
    down, the combo box immediately closes giving no time to even click
    on the dropdown. This doesn’t happen every time the combo is
    clicked, although it happens frequently. What I think is that the
    problem arises because the data grid tries to refresh the renderers
    and during this process, the existing combo is removed, thereby
    getting closed automatically. Please let me know of a work around.
    Thanks,
    Cheree

    hi hiwa,
    i have to add combo box in datagrid dynamically.
    it should append as and when i add the data in the above text boxes.
    thanks in advance.

  • Problem in showing combo box in the table

    Hello guys i just add up the combo box in the table but the problem is when i change the line in the table the combo disappear. i want it to be visible even if it is not in the selected row. i want that user can see the combo box in the table without clicking on it.
    Please help;

    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    Look in the page bottom !

  • JSP problem - drop down combo boxes

    Hi,
    I want to load a database table value into my HTML form's dropdown combo box.
    Actually I want to do this. I need to change employee information. To do this there is a form to enter empNo. Then it will display a .jsp page with the relevant fields of that employee. In this .jsp page, it has a drop down combo box for title. In my db the required title of that employee is Miss.
    But how could I display this value in this dropdown combo box. Then the user can change it as she wish.
    I try it like this way, but it isn't work.
    <select size="1" name="title" style="border: 1px solid #0000FF">
           <jsp:getProperty name="candidate" property="title" />
    </select>     Can anybody tell me hoe to solve this?
    Thanks.

    Hi,
    Thanks for your help.
    I have change that code, as follows.
    <select size="1" name="title" style="border: 1px solid #0000FF">
    <option value="" ><jsp:getProperty name="candidate" property="title" /></option>
    </select> Now it displays the correct title. But how can I display the other 2 options below this? that is Mr. and Mrs. Because the user must have the facility to select Miss. or Mrs. if there any changes she wish to apply.
    Note:
    If a user has a title - Mr. , then the other 2 titles (Miss,Mrs) should be display below it.
    How to solve this?
    Thanks

  • Edit combo box array

    Hello,
    I am trying to add a value to a specific combo box in a 2d array.
    lets say i have a 2d array of combo boxes, how can i add a value to the combo box in row 3 and colomn 4?
    Thank.

    Hey,
    I have an ini file with diffrent tests and every test has a diffrent settings, for example:
    [HO type_Intra ASN Handover]
    Type=INI VI
    Delay between H.O=5,2
    Trafic type=Smartbits,Ping
    Number of Handover=xxx
    [HO type_Inter ASN Handover]
    Type=INI VI
    Deleay between H.O=5,2
    Trafic type=Smartbits,Ping
    Number of Handover=xxx
    The idea is that for example delay between handovers is a combo box parameter with values of 5,2 and trafic type is also a combo box parameter but with values smartbit or ping and the number of handovers is a regular string how can i diplay those parameter for the user ? there can be more then 3 parameter...is there a solution ?

  • Problem in event handling of combo box in JTable cell

    Hi,
    I have a combo box as an editor for a column cells in JTable. I have a event listener for this combo box. When ever I click on the JTable cell whose editor is combo box,
    I get the following exception,
    Exception occurred during event dispatching:
    java.lang.NullPointerException
         at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.setDispatchComponent(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.mousePressed(Unknown Source)
         at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
         at java.awt.Component.processMouseEvent(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.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.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)
    Can any one tell me how to over come this problem.
    Thanks,
    Raghu

    Here's an example of the model I used in my JTable. I've placed 2 comboBoxes with no problems.
    Hope this helps.
    public class FileModel5 extends AbstractTableModel
    public boolean isEditable = false;
    protected static int NUM_COLUMNS = 3;
    // initialize number of rows to start out with ...
    protected static int START_NUM_ROWS = 0;
    protected int nextEmptyRow = 0;
    protected int numRows = 0;
    static final public String file = "File";
    static final public String mailName = "Mail Id";
    static final public String postName = "Post Office Id";
    static final public String columnNames[] = {"File", "Mail Id", "Post Office Id"};
    // List of data
    protected Vector data = null;
    public FileModel5()
    data = new Vector();
    public boolean isCellEditable(int rowIndex, int columnIndex)
    // The 2nd & 3rd column or Value field is editable
    if(isEditable)
    if(columnIndex > 0)
    return true;
    return false;
    * JTable uses this method to determine the default renderer/
    * editor for each cell. If we didn't implement this method,
    * then the last column would contain text ("true"/"false"),
    * rather than a check box.
    public Class getColumnClass(int c)
    return getValueAt(0, c).getClass();
    * Retrieves number of columns
    public synchronized int getColumnCount()
    return NUM_COLUMNS;
    * Get a column name
    public String getColumnName(int col)
    return columnNames[col];
    * Retrieves number of records
    public synchronized int getRowCount()
    if (numRows < START_NUM_ROWS)
    return START_NUM_ROWS;
    else
    return numRows;
    * Returns cell information of a record at location row,column
    public synchronized Object getValueAt(int row, int column)
    try
    FileRecord5 p = (FileRecord5)data.elementAt(row);
    switch (column)
    case 0:
    return (String)p.file;
    case 1:
    return (String)p.mailName;
    case 2:
    return (String)p.postName;
    catch (Exception e)
    return "";
    public void setValueAt(Object aValue, int row, int column)
    FileRecord5 arow = (FileRecord5)data.elementAt(row);
    arow.setElementAt((String)aValue, column);
    fireTableCellUpdated(row, column);
    * Returns information of an entire record at location row
    public synchronized FileRecord5 getRecordAt(int row) throws Exception
    try
    return (FileRecord5)data.elementAt(row);
    catch (Exception e)
    throw new Exception("Record not found");
    * Used to add or update a record
    * @param tableRecord
    public synchronized void updateRecord(FileRecord5 tableRecord)
    String file = tableRecord.file;
    FileRecord5 p = null;
    int index = -1;
    boolean found = false;
    boolean addedRow = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord5)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    { //update
    data.setElementAt(tableRecord, index);
    else
    if (numRows <= nextEmptyRow)
    //add a row
    numRows++;
    addedRow = true;
    index = nextEmptyRow;
    data.addElement(tableRecord);
    //Notify listeners that the data changed.
    if (addedRow)
    nextEmptyRow++;
    fireTableRowsInserted(index, index);
    else
    fireTableRowsUpdated(index, index);
    * Used to delete a record
    public synchronized void deleteRecord(String file)
    FileRecord5 p = null;
    int index = -1;
    boolean found = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord5)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    data.removeElementAt(i);
    nextEmptyRow--;
    numRows--;
    fireTableRowsDeleted(START_NUM_ROWS, numRows);
    * Clears all records
    public synchronized void clear()
    int oldNumRows = numRows;
    numRows = START_NUM_ROWS;
    data.removeAllElements();
    nextEmptyRow = 0;
    if (oldNumRows > START_NUM_ROWS)
    fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);
    fireTableRowsUpdated(0, START_NUM_ROWS - 1);
    * Loads the values into the combo box within the table for mail id
    public void setUpMailColumn(JTable mapTable, ArrayList mailList)
    TableColumn col = mapTable.getColumnModel().getColumn(1);
    javax.swing.JComboBox comboMail = new javax.swing.JComboBox();
    int s = mailList.size();
    for(int i=0; i<s; i++)
    comboMail.addItem(mailList.get(i));
    col.setCellEditor(new DefaultCellEditor(comboMail));
    //Set up tool tips.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for mail Id list");
    col.setCellRenderer(renderer);
    //Set up tool tip for the mailName column header.
    TableCellRenderer headerRenderer = col.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the Mail Id to see a list of choices");
    * Loads the values into the combo box within the table for post office id
    public void setUpPostColumn(JTable mapTable, ArrayList postList)
    TableColumn col = mapTable.getColumnModel().getColumn(2);
    javax.swing.JComboBox combo = new javax.swing.JComboBox();
    int s = postList.size();
    for(int i=0; i<s; i++)
    combo.addItem(postList.get(i));
    col.setCellEditor(new DefaultCellEditor(combo));
    //Set up tool tips.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for post office Id list");
    col.setCellRenderer(renderer);
    //Set up tool tip for the mailName column header.
    TableCellRenderer headerRenderer = col.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the Post Office Id to see a list of choices");
    }

  • Adding an event listener to combo box

    I am working on a mortgage calculator and I cannot figure out how to add an event listener to a combo box.
    I want to get the mortgage term and interest rate to calucate the mortgage using the combo cox. Here is my program.
    Modify the mortgage program to allow the user to input the amount of a mortgage
    and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year at 5.50%, and
    30 year at 5.75%. Use an array for the different loans. Display the mortgage payment
    amount. Then, list the loan balance and interest paid for each payment over the term
    of the loan. Allow the user to loop back and enter a new amount and make a new
    selection, with resulting new values. Allow user to exit if running as an application
    (can't do that for an applet though).
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.text.NumberFormat;
    import java.util.Locale;
    //creates class MortgageCalculator
    public class MortgageCalculator extends JFrame implements ActionListener {
    //creates title for calculator
         JPanel row = new JPanel();
         JLabel mortgageCalculator = new JLabel("MORTGAGE CALCULATOR", JLabel.CENTER);
    //creates labels and text fields for amount entered          
         JPanel firstRow = new JPanel(new GridLayout(3,1,1,1));
         JLabel mortgageLabel = new JLabel("Mortgage Payment $", JLabel.LEFT);
         JTextField mortgageAmount = new JTextField(10);
         JPanel secondRow = new JPanel();
         JLabel termLabel = new JLabel("Mortgage Term/Interest Rate", JLabel.LEFT);
         String[] term = {"7", "15", "30"};
         JComboBox mortgageTerm = new JComboBox(term);
         JPanel thirdRow = new JPanel();
         JLabel interestLabel = new JLabel("Interest Rate (%)", JLabel.LEFT);
         String[] interest = {"5.35", "5.50", "5.75"};
         JComboBox interestRate = new JComboBox(interest);
         JPanel fourthRow = new JPanel(new GridLayout(3, 2, 10, 10));
         JLabel paymentLabel = new JLabel("Monthly Payment $", JLabel.LEFT);
         JTextField monthlyPayment = new JTextField(10);
    //create buttons to calculate payment and clear fields
         JPanel fifthRow = new JPanel(new GridLayout(3, 2, 1, 1));
         JButton calculateButton = new JButton("CALCULATE PAYMENT");
         JButton clearButton = new JButton("CLEAR");
         JButton exitButton = new JButton("EXIT");
    //Display area
         JPanel sixthRow = new JPanel(new GridLayout(2, 2, 10, 10));
         JLabel displayArea = new JLabel(" ", JLabel.LEFT);
         JTextArea textarea = new JTextArea(" ", 8, 50);
    public MortgageCalculator() {
         super("Mortgage Calculator");                     //title of frame
         setSize(550, 350);                                             //size of frame
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container pane = getContentPane();
         GridLayout grid = new GridLayout(7, 3, 10, 10);
         pane.setLayout(grid);
         pane.add(row);
         pane.add(mortgageCalculator);
         pane.add(firstRow);
         pane.add(mortgageLabel);
         pane.add(mortgageAmount);
         pane.add(secondRow);
         pane.add(termLabel);
         pane.add(mortgageTerm);
         pane.add(thirdRow);
         pane.add(interestLabel);
         pane.add(interestRate);
         pane.add(fourthRow);
         pane.add(paymentLabel);
         pane.add(monthlyPayment);
         monthlyPayment.setEnabled(false);
         pane.add(fifthRow);
         pane.add(calculateButton);
         pane.add(clearButton);
         pane.add(exitButton);
         pane.add(sixthRow);
         pane.add(textarea); //adds texaarea to frame
         pane.add(displayArea);
         setContentPane(pane);
         setVisible(true);
         //Adds Listener to buttons
         calculateButton.addActionListener(this);
         clearButton.addActionListener(this);
         exitButton.addActionListener(this);
         mortgageTerm.addActionListener(this);
         interestRate.addActionListener(this);
    public void actionPerformed(ActionEvent event) { 
         Object command = event.getSource();
         JComboBox mortgageTerm = (JComboBox)event.getSource();
         String termYear = (String)mortgageTerm.getSelectedItem();
    if (command == calculateButton) //calculates mortgage payment
         int year = Integer.parseInt(mortgageTerm.getText());
         double rate = new Double(interestRate.getText()).doubleValue();
         double mortgage = new Double(mortgageAmount.getText()).doubleValue();
         double interest = rate /100.0 / 12.0;
         double monthly = mortgage *(interest/(1-Math.pow(interest+1,-12.0 * year)));
                   NumberFormat myCurrencyFormatter;
                   myCurrencyFormatter = NumberFormat.getCurrencyInstance(Locale.US);
                   monthlyPayment.setText(myCurrencyFormatter.format(monthly));
         if(command == clearButton) //clears all text fields
                   mortgageAmount.setText(null);
                   //mortgageTerm.setText(null);
                   //interestRate.setText(null);
                   monthlyPayment.setText(null);
              if(command == exitButton) //sets exit button
                        System.exit(0);
         public static void main(String[] arguments) {
              MortgageCalculator mor = new MortgageCalculator();

    The OP already did this to both JComboBoxes.
    mochatay, here is a new actionPerformed method for you to use.
    I've improved a few things here and there...
    1) You can't just cast the ActionEvent's source into a JComboBox!
    What if it was a JButton that fired the event? Then you would get ClassCastExceptions (I'm sure you did)
    So check for all options, what the source of the ActionEvent actually was...
    2) You can't assume the user will always type in valid data.
    So enclose the Integer and Double parse methods in try-catch brakcets.
    Then you can do something when you know that the user has entered invalid input
    (like tell him/her what a clumsy idiot they are !)
    3) As soon as user presses an item in any JComboBox, just re-calculate.
    I did this here by programmatically clicking the 'Calculate' button.
    Alternatively, you could have a 'calculate' method, which does everything inside the
    if(command==calculateButton) if-block.
    This will be called when:
    a)calculateButton is pressed
    b)when either of the JComboBoxes are pressed.
    public void actionPerformed (ActionEvent event)
            Object command = event.getSource ();
            if (command == calculateButton) //calculates mortgage payment
                int year = 0;
                double rate = 0;
                double mortgage = 0;
                double interest = 0;
                /* If user has input invalid data, tell him so
                and return (Exit from this method back to where we were before */
                try
                    year = Integer.parseInt (mortgageTerm.getSelectedItem ().toString ());
                    rate = new Double (interestRate.getSelectedItem ().toString ()).doubleValue ();
                    mortgage = new Double (mortgageAmount.getText ()).doubleValue ();
                    interest = rate / 100.0 / 12.0;
                catch (NumberFormatException nfe)
                    /* Display a message Dialogue box with a message */
                    JOptionPane.showMessageDialog (this, "Error! Invalid input!");
                    return;
                double monthly = mortgage * (interest / (1 - Math.pow (interest + 1, -12.0 * year)));
                NumberFormat myCurrencyFormatter;
                myCurrencyFormatter = NumberFormat.getCurrencyInstance (Locale.US);
                monthlyPayment.setText (myCurrencyFormatter.format (monthly));
            else if (command == clearButton) //clears all text fields
                /* Better than setting it to null (I think) */
                mortgageAmount.setText ("");
                //mortgageTerm.setText(null);
                //interestRate.setText(null);
                monthlyPayment.setText ("");
            else if (command == exitButton) //sets exit button
                System.exit (0);
            else if (command == mortgageTerm)
                /* Programmatically 'clicks' the button,
                As is user had clicked it */
                calculateButton.doClick ();
            else if (command == interestRate)
                calculateButton.doClick ();
            //JComboBox mortgageTerm = (JComboBox) event.getSource ();
            //String termYear = (String) mortgageTerm.getSelectedItem ();
        }Hope this solves your problems.
    I also hope you'll be able to learn from what I've indicated, so you can use similar things yourself
    in future!
    Regards,
    lutha

Maybe you are looking for

  • Create PO using Idoc with free goods

    Hi guys, i'am currently working on a projekt i need to create a purchase order containing free goods. We've already tested the PORDCR/PORDCR1 message and Idoc types PORDCR101/102 with BAPI's IDOC_INPUT_PORDCR1  - w/ self-defined process code (via we4

  • Dynamic file name for report export to csv

    If "Enable CSV output" = "YES" for a report region titled "Invoices", the default file name is "Invoices.csv". If I have a parameter, Pn_MONTH, for the month (e.g. Jan 2010, Feb 2010, etc.) and the report only shows data for that month, I would like

  • Yahoo! Cannot add files to email.

    Yahoo! Ever since I downloaded Safari 5, I cannot add files to emails (esp photos). Safari would freeze up, and I would have to power down and reboot in order to surf. Any solutions to this matter other than switching to gmail?

  • SQL "LIKE" statement isn't working right -- help please!

    Good day everyone, I thought about putting this in the "SQL on Oracle" forum, but it looked like those messages were geared more toward the Oracle platform itself, so here I am.  I apologize if this isn't the best forum. I have the following SQL stat

  • Trying to find ResultSet empty or not - Error - please help

    Purpose of the code : I am trying to see if the customer or user is in the database. Error : Cannote convert boolean to resultset <%@ page language="java" contentType="text/html; charset=ISO-8859-1"      pageEncoding="ISO-8859-1"%> <%@page import="ja