getCellEditor (...) 메소드를 대체하십시오. 예를 들어;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
public class TableComboBoxByRow extends JFrame
{
List<TableCellEditor> editors = new ArrayList<TableCellEditor>(3);
public TableComboBoxByRow()
{
// Create the editors to be used for each row
String[] items1 = { "Red", "Blue", "Green" };
JComboBox comboBox1 = new JComboBox(items1);
DefaultCellEditor dce1 = new DefaultCellEditor(comboBox1);
editors.add(dce1);
String[] items2 = { "Circle", "Square", "Triangle" };
JComboBox comboBox2 = new JComboBox(items2);
DefaultCellEditor dce2 = new DefaultCellEditor(comboBox2);
editors.add(dce2);
String[] items3 = { "Apple", "Orange", "Banana" };
JComboBox comboBox3 = new JComboBox(items3);
DefaultCellEditor dce3 = new DefaultCellEditor(comboBox3);
editors.add(dce3);
// Create the table with default data
Object[][] data =
{
{"Color", "Red"},
{"Shape", "Square"},
{"Fruit", "Banana"},
{"Plain", "Text"}
};
String[] columnNames = {"Type","Value"};
DefaultTableModel model = new DefaultTableModel(data, columnNames);
JTable table = new JTable(model)
{
// Determine editor to be used by row
public TableCellEditor getCellEditor(int row, int column)
{
int modelColumn = convertColumnIndexToModel(column);
if (modelColumn == 1 && row < 3)
return editors.get(row);
else
return super.getCellEditor(row, column);
}
};
JScrollPane scrollPane = new JScrollPane(table);
getContentPane().add(scrollPane);
}
public static void main(String[] args)
{
TableComboBoxByRow frame = new TableComboBoxByRow();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
@hotveryspicy가 원하는 수정을 명확히하십시오 말해보십시오. "다음 셀로 이동"이란 의미는 무엇입니까? 값을 다음 열로 이동하는 것과 마찬가지로? 또는 한 줄 아래로 포커스를 이동 하시겠습니까? 그리고 "각 셀에 대해 콤보 상자를 만들고 싶지 않고, 각 셀에 대해 하나의 콤보 상자를 만들고 싶지 않습니까? * 열 * 당 하나만 의미합니까? – SeKa