這篇文章主要為大家展示了“在表格中Swing如何增加列表框”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“在表格中Swing如何增加列表框”這篇文章吧。
成都創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站制作、做網(wǎng)站與策劃設(shè)計,鲅魚圈網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:鲅魚圈等地區(qū)。鲅魚圈做網(wǎng)站價格咨詢:18982081108
Swing增加下拉列表框
在表格的一列中Swing增加下拉列表框,首先獲得列表對象,在設(shè)置表列編輯,將下拉列表框作為默認列編輯對象設(shè)置到表列編輯對象中
importjava.awt.BorderLayout; importjava.awt.Dimension; importjavax.swing.JFrame; importjavax.swing.JPanel; importjavax.swing.JScrollPane; importjava.awt.Rectangle; importjavax.swing.JTable; importjavax.swing.table.TableColumn; importjavax.swing.DefaultCellEditor; importjavax.swing.JComboBox; importjavax.swing.JCheckBox; publicclassJComboBoxSecondextendsJFrame{ JPanelcontentPane; JScrollPanejScrollPane1=newJScrollPane(); Object[][]objContent={{"Tom","Hanks","Java","24","true"},{"Ben","John", "Java","25","true"},{"Michael","Fred","Java","26","true"}, {"Steve","Bell","Java","27","true"}, {"Jim","Lan","Java","29","true"} }; Object[]objHead={"名字","姓氏","技能","年齡","是否屬實"}; JTablejTable1=newJTable(objContent,objHead); JComboBoxjComBo=newJComboBox(); JCheckBoxjCheck=newJCheckBox(""); publicJComboBoxSecond(){ try{ setDefaultCloseOperation(EXIT_ON_CLOSE); jbInit(); }catch(Exceptionexception){ exception.printStackTrace(); } } /** *Componentinitialization. * *@throwsjava.lang.Exception */ privatevoidjbInit()throwsException{ contentPane=(JPanel)getContentPane(); contentPane.setLayout(null); setSize(newDimension(467,401)); setTitle("FrameTitle"); jScrollPane1.setBounds(newRectangle(11,20,442,337)); jComBo.addItem("Java"); jComBo.addItem("Orcale"); jComBo.addItem("Linux"); jComBo.addItem("Unix"); jComBo.addItem("C#"); TableColumntableCol=jTable1.getColumnModel().getColumn(2); tableCol.setResizable(false); TableColumntableColCheck=jTable1.getColumnModel().getColumn(4); tableCol.setCellEditor(newDefaultCellEditor(jComBo)); tableColCheck.setCellEditor(newDefaultCellEditor(jCheck)); contentPane.add(jScrollPane1); jScrollPane1.getViewport().add(jTable1); } }
以上是“在表格中Swing如何增加列表框”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!