Only the most recent comboBox values are showing up in both rows.
UPDATED MVCE Example:
package main;
import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
public class SwingDemo {
public static void main(String[] argv) throws Exception {
DefaultTableModel model = new DefaultTableModel();
model.addColumn("Column 1");
JTable table = new JTable(model);
Font font = new Font("Verdana", Font.PLAIN, 12);
table.setFont(font);
table.setRowHeight(30);
table.setBackground(Color.orange);
table.setForeground(Color.white);
JFrame frame = new JFrame();
frame.setSize(600, 400);
frame.add(new JScrollPane(table));
frame.setVisible(true);
//add 1st row
model.addRow("".split(""));
TableColumn testColumn1stRow = table.getColumnModel().getColumn(0);
JComboBox<String> comboBoxTest = new JComboBox<String>();
ArrayList<String> testArray = new ArrayList<String>();
testArray.add("one");
testArray.add("two");
testArray.add("three");
for (int i = 0; i < testArray.size(); i++) {
comboBoxTest.addItem(testArray.get(i));
}
testColumn1stRow.setCellEditor(new DefaultCellEditor(comboBoxTest));
//add 2nd row
model.addRow("".split(""));
TableColumn testColumn2ndRow = table.getColumnModel().getColumn(0);
JComboBox<String> comboBoxTest2 = new JComboBox<String>();
ArrayList<String> testArray2 = new ArrayList<String>();
testArray2.add("four");
testArray2.add("five");
testArray2.add("six");
for (int i = 0; i < testArray2.size(); i++) {
comboBoxTest2.addItem(testArray2.get(i));
}
testColumn2ndRow.setCellEditor(new DefaultCellEditor(comboBoxTest2));
}
}
Essentially every time I add a row it runs this code and then every row in column has the value of the most recently added combobox.
Any ideas on how to get around this?