简体   繁体   中英

Editable cell and growable Jtable Implementation

I have a JTable with Customized CellRenderer and CellEditor, Intially the table is loaded with
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. 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. 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)...

Thanks a lot in Advance :)

Kindly let us assume jTable2 be your JTable variable name and TextField be your JTextField variable name. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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