如题,如何实现下图功能?
....不知怎么上传图片‘’
------解决方案--------------------
- Java code
import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.*;import javax.swing.event.*;public class TestTableFrame extends JFrame{ private JTable table; private DefaultTableModel model; public TestTableFrame() { Object[] columnNames = {"列1", "列2", "列3"}; model = new DefaultTableModel(columnNames, 10); table = new JTable(model); TableColumn comboColumn = table.getColumn("列2"); //获得所在列 JComboBox combo = new JComboBox(); combo.addItem("1"); combo.addItem("2"); comboColumn.setCellEditor(new DefaultCellEditor(combo)); //将该列的CellEditor设为一个选择框 add(new JScrollPane(table)); } public static void main(String[] args) { JFrame frame = new TestTableFrame(); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }}