I\'ve been trying for hours, different things and searching everywhere for a solution, but I can not get my table in addScoreCardUpper()
to show up. I get an ho
Try any one
scrollPane = new JScrollPane(table);
or
scrollPane = new JScrollPane(table,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
or
scrollPane.getViewport().add(table);
This is your problem:
scrollPane.add(table);
This does not add the JTable to the JScrollPane's viewport's view which is where you want it, but rather completely replaces the JScrollPane's viewport with the JTable, making the JScrollPane completely nonfunctional. Instead set the table as the JScrollPane's viewportview:
scrollPane.setViewportView(table);
Do either this or pass the table into the JScrollPane's constructor which does pretty much the same thing:
JScrollPane scrollPane = new JScrollPane(table,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
This is all well explained in the JScrollPane API, and you will want to give it a look for the important details.
Edit
Your code also calls setVisible(true)
on the JFrame before adding all components which can lead to trouble. You'll want to avoid doing this.