[英]How to add a JComboBox to a JTable cell?
我正在尝试将JComponents添加到JTable Cells。 我是否实施CellRenderer或CellEditor?
您也可以通过将JComboBox(或JCheckBox或JTextField)的实例传递给构造函数来使用DefaultCellEditor执行此操作。
1-创建一个JCombobox
并在其中插入您想要的信息,如下所示:
JComboBox<String> sport = new JComboBox<String>();
sport.addItem("foot");
sport.addItem("hand bool");
sport.addItem("****");
2-创建JTable
并将表模式设置为此表,如:
Vector<String> title = new Vector<String>
title.add("id");
title.add("sport");
Vector<Vector<String>> rows = new Vector<Vector<String>>();
rows.addItem("1");
rows.addItem("2");
JTable table = new JTable(rows, title);
3-您将JComboBox放在JTable单元格中,如下所示:
table.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(sport));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.