开发者

Problem in giving input to JTable from keyboard

开发者 https://www.devze.com 2023-01-31 12:24 出处:网络
I want to know how to give input to the cell in a jtable from keyboard. And 开发者_StackOverflow社区when I try to do this when I move on to next cell the previous enter data is removed or erased auto

I want to know how to give input to the cell in a jtable from keyboard.

And 开发者_StackOverflow社区when I try to do this when I move on to next cell the previous enter data is removed or erased automatically.

I am using abstracttable model for creating jtable.


iam using abstracttable model for creating jtable....

and when i try to do dis when i move on to next cell the previous enter data is removed or erased automatically....

The AbstractTableModel doesn't implement the setValueAt(...) method. So unless your custom model implements this correctly you will lose the data entered in the editor.

I suggest you keep it simple and use the DefaultTableModel until you better understand how a JTable works. The code would be:

DefaultTableModel model = new DefaultTableModel(...);
JTable table = new JTable( model );


As discussed in How to Use Tables, you can specify a renderer and editor for each column in a JTable, or you can override getColumnClass() to obtain the default for any of the listed data types. In addition, you might compare what you're doing with one of the examples listed there or edit your question to include an sscce.


Sounds like you are not saving the data entered into your model. Secondly, I would suggest extending DefaultTableModel instead of AbstractTableModel unless you have a good reason.

0

精彩评论

暂无评论...
验证码 换一张
取 消