Comment remplir une combobox à partir d'un JTable en Java

rosefransaise Posted messages 2 Status Member -  
juliencolin54 Posted messages 238 Status Member -
Hello everyone

My problem is actually that I need to fill a JComboBox with the values from one of the columns of a JTable.

It should be quite simple, but oh well...

Thanks in advance

Configuration: Windows 7 / Firefox 23.0

3 answers

  1. juliencolin54 Posted messages 238 Status Member 55
     
    Hello,

    You can do it like this:

    /*
    ** Definition
    */
    private JTable table = new JTable();
    private JComboBox combo = new JComboBox();

    /*
    ** Initialization of objects
    */

    /*
    ** Retrieving the value at the
    ** (row_index + 1) column
    ** (col_index + 1) row
    */
    table.getModel().getValueAt(row_index, col_index);

    /*
    ** Adding a value to the JComboBox
    */
    combo.addItem(SOMETHING);

    Hoping this helps you, best regards.
    --
    Software is like sex, it's better when it's free - Linus Torvald
    0
  2. rosefransaise Posted messages 2 Status Member
     
    Thank you for your help, have a great day.
    0
  3. juliencolin54 Posted messages 238 Status Member 55
     
    It's a pleasure, to you too.

    --
    Software is like sex, it's better when it's free - Linus Torvald
    0