JTable Cell Editor - JComboBox column

Discussion in 'Java' started by Chris, Jun 14, 2005.

  1. Chris

    Chris Guest

    Hello,

    I did create a jTable using cell editor in order to have one column as
    a jComboBox. Everything works fine, bu I have a limitation.
    In the extract example below, the column #2 was defined as jComboBox
    with values from 0 to 4.
    When I populate the jTable, for each row in column 2, I can select the
    values from jCombo.

    Here is my question: I need to have different content of jComboBox for
    each row.

    e.g. :
    row #1 has values from 0 to 4, selected from jComboBox / this
    jComboBox should display only values 0 to 4
    row #2 has values from 5 to 10 , selected from jComboBox / this
    jComboBox should display only values 5 to 10
    row #3 has values from 11 to 15,f selected from jComboBox / this
    jComboBox should display only values 11 to 15...

    Is that possible in the way I did start? How should I dynamically
    create and populate jComboBox-es to have different content for each
    row of jTable and how to associate these jComboBox to jTable? Could
    you please let me find out how should I continue for my situation.

    Thanks,
    Chris

    ....
    Vector descriptionList = new Vector();
    JTable jTable1

    Object obj;

    for (int i = 0; i < 4; i++)
    descriptionList.add(new Integer(i));//add some values

    JComboBox myJComboBox = new JComboBox(descriptionList);

    TableCellEditor myCellEditor = new DefaultCellEditor(myJComboBox );

    TableColumnModel myCellModel = jTable1.getColumnModel();

    TableColumn myColumn = myCellModel.getColumn(2);//column # as jCombo

    myColumnn.setCellEditor(myCellEditor);
    ....
    //cellsTab & columnNames are defined and populated
    jTable1 = new JTable(cellsTab, columnNames);
     
    Chris, Jun 14, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tivo Escobar
    Replies:
    1
    Views:
    7,555
    manusa
    Apr 12, 2007
  2. news.rcn.com
    Replies:
    1
    Views:
    9,815
    Chris Smith
    Jul 12, 2004
  3. Yulia
    Replies:
    1
    Views:
    705
    Andrew Thompson
    Jul 4, 2005
  4. Replies:
    2
    Views:
    2,343
  5. Replies:
    0
    Views:
    721
Loading...

Share This Page