I am developing a Java application that uses a JTable. I want to allow the user to enter data in a JTable that can later be printed or saved as PDF file. The issues is: Suppose the user has entered some data and the cursor is on the last cell of the row in a table (I have uploaded an image-suppose the cursor is on the highlighted cell).How do I make it in such a way that when a user presses the Enter Button(Keyboard button) the application will add/append a new row that is empty to the table so that the user can fill in other data.
Nation 0
Lord
Recommended Answers
Jump to PostWhich part of that is the problem? Responding to the enter button, adding a blank row to a table, or something else?
Jump to PostHere's the trick:
JTable is just a view, the actual structure and data is in itsTableModel
.
Get your JTable's TableModel(DefaultTableModel) myTable.getModel()
, and add a new row to thataddRow(Object[] data)
Jump to PostYou're getting that error because the constructor you used to create your JTable is a simple one that doesn't build a TabelModel that supports adding rows.
DefaultTableModel is the obvious first choice. To get a DefaultTableModel you simply ask for one, ie
DefaultTableModel tm = new DefaultTableModel(data, …
All 9 Replies
JamesCherrill 4,733
Most Valuable Poster Team Colleague Featured Poster
Nation 0
Lord
JamesCherrill 4,733
Most Valuable Poster Team Colleague Featured Poster
Nation 0
Lord
JamesCherrill 4,733
Most Valuable Poster Team Colleague Featured Poster
Nation 0
Lord
Nation 0
Lord
JamesCherrill 4,733
Most Valuable Poster Team Colleague Featured Poster
Nation 0
Lord
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.