Auto update JTable after INSERT statement - java

I am using Derby and Eclipse/Java. I have a table in a database which populates a JTable in a scrollable frame. I enter data for a new row in textedit fields and commit to the database with an INSERT sql statement. I want the displayed table to automatically update and have googled extgensively to find out how to do this. I understand that fireTableRowsInserted should trigger this. I have a tableModel class extending AbstractTableModel. If I call fireTableRowsInserted from my entry class the table doesnt update. From searching I thought that the table listens for this event - do I have to create the listener, if so I havent been able to find a clear(to me!) indication of how this is done and would appreciate a pointer to a source that would help.
Is there a good book or online reference on using databses,sql and a Visual Designer with Java?

Related

adding pagination to all tables using jtable in jsp

I have done pagination to a simple table using jtable in jsp.But it only works to that table.I have write a code which will give drop down of all tables present in mysql database.Now how to write pagination code in the way that if i select a table it should display all the data in that table using pagination and CRUD operations from User Interface .I have done it for only one table .Now please give an idea how to make these tables to display the dynamically selected table with pagination.
You will need to generate the jtable configuration on the selection of your table in the dropdown.
Create the jtable configuration for all your table then change (destroy the jtable using $('div1').jtable('destroy') initialize your div with selected table configuration.
Here is the answer for this requirement (stackoverflow.com/questions/27644483/dynamic-fields-using-jquery-in-jtable)

How to make filterable to jtable record using netbeans ide

There are many rows on above showing jtable. I want to filter record by short code. If I type short code like 1234 it should be display only short code 1234 associated row on jtable.
Thanks
You're going to have write the code...Start by checking out how to use tables, in particular sorting and filtering
The basic requirement would be to attach an ActionListener to both the field and button (you can do this from the form editor if you wish).
Within the actionPerformed event handler method, you need to create a RowFilter and apply it to the tables RowSorter.
A table can be configured to automatically create a row sorter by setting the autoCreateRowSorter property to true.
It's all explained nicely in the linked tutorials...
And another example

JTables with Buttons to delete things

i have several Tables which display things like products which are saved in a database. So to get this products displayed i get a list from the database and give the list to the tablemodel.
Now i want a delete button in every row with which i can delete the product from the database.
Are there some good ways to do this? Right now i have implemented something that feels wrong. I have custom button which saves its row when its initialized and that makes a callback from the table (custom class extending jtable) to the view which then calls the controller to delete the entry from DB.
Check out Table Button Column by #camickr.

File to JTable, JTable to file

I have been working on JTable,
My project:
read data from database (I finished this task and able to display in JTable).
then display and save data into subgroups into file (text/excel).
I have basic knowledge on JTable and using the some example code, I could manage to finish my first task. Then struck on second task.
for example
name| email|
name1|email#email.com
name2|email2#email.com
(I finished this task and able to display in JTable)
Then
when user clicks any row
then displayed new table
name|Email
display----
then user should able to save the group with groupname
Can anyone has idea about how to update the table dynamically and any suggestions?
Can anyone has idea about how to update the table dynamically and any
suggestions?
If you are using DefaultTableModel then you have methods like addRow(..) which will append a row in the JTable. Updating the existing rows in JTable is done using setValueAt(..) method. No need to call fireXXXMethod for DefaultTableModel.
Or
If your are using AbstractTableModel then use the setValueAt(..) method and call fireXXXMethod in the table model to refresh the table data.

Updating JTable after inline edit

I have 2 classes, one to make a frame and the other to handle and implement the interface TableModel. When editing cells inline and updating the values in the class that implements TableModel I then need to refresh the table to show the updated data (as the table needs to auto sort thus when I inline edit a cell the rows may need to be re-ordered). The problem I'm having is after updating the data I can't figure out how to refresh the table, I've tried a hacky way of refreshing it when you click off the cell or press enter but I feel there could be a more elegant solution, any ideas?
The TableModel is responsible for invoking the fireTableCellChanged(...) method when data is changed in the model. Sorting will then happen automatically.
Read the JTable API and follow the link to the Swing tutorial on How to Use Tables for more information about TableModels and sorting.
I suggest you just use the DefaultTableModel so you don't have to worry about this since it implements all the TableModel methods.

Categories