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

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. 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
    1. Thank you for your help, have a great day.
      0
      1. It's a pleasure, to you too.

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