您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“在表格中Swing如何增加列表框”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“在表格中Swing如何增加列表框”這篇文章吧。
Swing增加下拉列表框
在表格的一列中Swing增加下拉列表框,首先獲得列表對(duì)象,在設(shè)置表列編輯,將下拉列表框作為默認(rèn)列編輯對(duì)象設(shè)置到表列編輯對(duì)象中
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={"名字","姓氏","技能","年齡","是否屬實(shí)"}; 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)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。