我有一个简单的 JTable:
String[] columnNames = {"Freetext",
"Numbers only",
"Combobox"};
Object[][] data = {
{"Kathy", new Integer(21), "Female"},
{"John", new Integer(19), "Male"},
{"Sue", new Integer(20), "Female"},
{"Joe", new Integer(22), "Male"}
};
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setAutoCreateRowSorter(true);
table.setFillsViewportHeight(true);
TableColumn comboboxCol = table.getColumnModel().getColumn(2);
JComboBox comboBox = new JComboBox();
comboBox.addItem("Male");
comboBox.addItem("Female");
comboboxCol.setCellEditor(new DefaultCellEditor(comboBox));
table.getColumnModel().getColumn(1).setCellEditor(new IntegerEditor(0, 100));
当我单击列标题时,它将在升序和降序排序之间交替。我想再添加一个列标题,该列标题在点击时会有所不同,而其他标题保留它们的行为。你会怎么做?