Swing增加下拉列表框
在表格的一列中Swing增加下拉列表框,首先获得列表对象,在设置表列编辑,将下拉列表框作为默认列编辑对象设置到表列编辑对象中
1.importjava.awt.BorderLayout;
2.importjava.awt.Dimension;
3.
4.importjavax.swing.JFrame;
5.importjavax.swing.JPanel;
6.importjavax.swing.JScrollPane;
7.importjava.awt.Rectangle;
8.importjavax.swing.JTable;
9.importjavax.swing.table.TableColumn;
10.importjavax.swing.DefaultCellEditor;
11.importjavax.swing.JComboBox;
12.importjavax.swing.JCheckBox;
13.
14.publicclassJComboBoxSecondextendsJFrame{
15.JPanelcontentPane;
16.JScrollPanejScrollPane1=newJScrollPane();
17.Object[][]objContent={{"Tom","Hanks","Java","24","true"},{"Ben","John",
18."Java","25","true"},{"Michael","Fred","Java","26","true"},
19.{"Steve","Bell","Java","27","true"},
20.{"Jim","Lan","Java","29","true"}
21.};
22.Object[]objHead={"名字","姓氏","技能","年龄","是否属实"};
23.JTablejTable1=newJTable(objContent,objHead);
24.JComboBoxjComBo=newJComboBox();
25.JCheckBoxjCheck=newJCheckBox("");
26.publicJComboBoxSecond(){
27.try{
28.setDefaultCloseOperation(EXIT_ON_CLOSE);
29.jbInit();
30.}catch(Exceptionexception){
31.exception.printStackTrace();
32.}
33.}