Reputation: 119
I'm having a problem with displaying a JTable
in a JPanel
. I'm having the user press a button and within this button the table should generate the table and put in an already existing panel, now when I tried to open it in a new JFrame
the data shows perfectly but I want to show it in a JPanel
.
Code:
files = c.RequestFile("list"); //gets the data of files
Object[][] filesArray = new Object[files.size()][1];
int size = 0;
for (FileInfo fileInfo : files) {
filesArray[size][0] = fileInfo.getName();
size++;
}
fileTablePanel.setLayout(new BorderLayout());
fileTablePanel.add(new JScrollPane(createTable(filesArray)));
Upvotes: 0
Views: 618
Reputation: 208944
You want to look into using a TableModel
. What you are currently doing is trying to replace one JTable
with another JTable
. That is totally unnecessary. You should just manipulate the data of the TableModel
.
You can see more at How to use Tables. You can focus on the section Creating a Table Model
Upvotes: 4
Reputation: 3309
After adding the new content to the panel, you need to repaint the panel to the screen:
fileTablePanel.revalidate();
fileTablePanel.repaint();
It works when you popup a new JFrame since it's the first time the JFrame is painted to the screen.
Upvotes: 0