Skip to content
Advertisement

JTable becomes blank after executing update on table? [closed]

I am trying to write some software where when a user adds a new entry to a SQL database, my JTable showing the entries in the database updates. Currently, when the method updateTable(Object[][] data) is called, it results in the table becoming blank.

Would anyone know of a fix for this type of issue?

Here is the code for the method:

JavaScript

Here is the code which calls updateTable():

JavaScript

Advertisement

Answer

JavaScript

Even though you add data to the TableModel you didn’t add any column names so as far as the table is concerned there are 0 columns to display.

Your code should be something like:

JavaScript

Or a better approach would be to use:

JavaScript

This will keep the existing columns and just add the data.

Also you don’t need to recreate the row array. You already have the data as a row in your 2D array:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement