Clearing JScrollPane, but cannot then "join" tables

I am creating an application in which I have 3 panels with buttons that dynamically create buttons on the next panel depending on the choice, by pressing the last button, the data table obtained using the SQL query will be displayed:

[buttonPane1] [buttonPane2] [buttonPane3] [table]

If the user pressed a button on all 3 panels, and then wants to change his choice on button panel 1, he will select options in button panel 2 and using

buttonPanel3.removeAll();
buttonPanel3.repaint();

I can clear the third panel of buttons, my problem is how to clear the table. I want to remove it from the Table ScrollPanel, but if I try

tableScrollPanel.removeAll();

it just means the table is never displayed.

How to delete any current table, but allow "reload" the table? I do this to create and β€œattach” a table

jTableTemp.setModel(new DefaultTableModel(
                    tableContent, tableTitles));
tableScrollPanel.setViewportView(jTableTemp);

thank you very much

+3
source share
1 answer

Try setting the table model to DefaultTableModel with empty data and source headers, and then redraw. As long as you have a JScollPane wrapped around a JTable, headers should appear, suggesting that this is what you want.

Alternatively, you can set the viewport to a new JTable instance with new headers.

+2
source

Source: https://habr.com/ru/post/1775847/


All Articles