简体   繁体   English

可编辑单元格和可扩展Jtable实现

[英]Editable cell and growable Jtable Implementation

I have a JTable with Customized CellRenderer and CellEditor, Intially the table is loaded with 我有一个带有自定义CellRenderer和CellEditor的JTable,最初该表已加载
a list of values Say with 12 rows and 5 colums, I have a JTextField at the top of the table in which I applied KeyListener and made the Textfield to display like a JComboBox with a list of values as soon as first 3 characters typed in that field, eg. 值列表例如,具有12行5列的表,我在表的顶部有一个JTextField,在其中应用了KeyListener并使Textfield像带有值列表的JComboBox一样显示,只要在其中键入前三个字符领域,例如 Typing 'met' will display all the medicine names starting with "met", now what I want to do is I have to Implement that Textfield into the Jtable's last row's 2nd column Say 13th row in the situation I mentioned above. 键入“ met”将显示所有以“ met”开头的药物名称,现在我要做的是在上述情况下,必须将Textfield实现到Jtable的最后一行的第二列中,即说第13行。 and after selecting any 1 medicine from the list of displayed value the JTable could Add a row dynamically and insert a new row with that search textfield, Please Suggest me an Idea and Code for this, also guide me how to apply cellrenderer and celleditor for a particular cell(Cell which contains the dynamic search textfield)... 从显示值的列表中选择任何一种药物后,JTable可以动态添加一行并在该搜索文本字段中插入新行,请为此提供一个建议和代码,并指导我如何将cellrenderer和celleditor用于特定单元格(包含动态搜索文本字段的单元格)...

Thanks a lot in Advance :) 非常感谢预先:)

Kindly let us assume jTable2 be your JTable variable name and TextField be your JTextField variable name. 请让我们假设jTable2是您的JTable变量名称,而TextField是您的JTextField变量名称。 Then use the following code with the keylisterner of the text field to get what is wanted:- 然后将以下代码与文本字段的键列表器一起使用以获取所需内容:-

javax.swing.table.DefaultTableModel dft= (javax.swing.table.DefaultTableModel)   
jTable2.getModel();
jTable2.setModel(dft);
dft.addRow(new Object[1]);
jTable2.setValueAt(TextField.getText(),jTable2.getRowCount()-1,1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM