I have a problem resizing some of my components in a Java application. When I resize the main JFrame, they retain their original size instead of filling the surrounding component.
For example, in my program I have a JTabbedPane inside the tab of another JTabbedPane (which is basically a JFrame). I do the tabs added to the inner JTabbedPane, fill all the surrounding space through various .setPreferredSize (). And then when I resize the JFrame by dragging the corner of the window, the tabs of the external JTabbedPane change simply, but the JTabbedPane inside it remains the same.
The same thing happens when I test it with JScrollPane: the outer size of the JTabbedPane with JScrollPane remains the same size.
Below is the code for creating tabbed panels if you see something obvious that I missed. These are tabPane / jsp objects in createEndGamePane () than resizing when resizing a JFrame. mainTabPane resizes as it should.
class MyFrame extends JFrame {
private JTabbedPane mainTabPane;
private JPanel endGameInfo;
private void createTabbedCenterPane(){
this.mainTabPane = new JTabbedPane();
this.endGameInfo = new JPanel();
this.createEndGamePane();
this.mainTabPane.addTab("Turneringschema", null, this.scheduleHolder, "Spelschemat för turneringen");
this.mainTabPane.addTab("Grupper & Pooler", null, this.poolInfo, "Information om grupper, lag och pooler");
this.mainTabPane.addTab("Slutspelsträd", null, this.endGameInfo, "Information om slutspelen");
this.add(this.mainTabPane, BorderLayout.CENTER);
}
private void createEndGamePane(){
JTabbedPane tabPane = new JTabbedPane();
tabPane.setPreferredSize(this.endGameInfo.getSize());
for (int i = 0; i < this.tournament.data.getGroups().size(); i++) {
EndGame e = this.tournament.data.getEndGames().get(i);;
EndGameTreeCanvas gameTree = new EndGameTreeCanvas(e, this.endGameInfo.getSize());
JScrollPane jsp = new JScrollPane(gameTree);
jsp.setPreferredSize(tabPane.getSize());
jsp.setBorder(BorderFactory.createEmptyBorder());
tabPane.addTab(this.tournament.data.getGroups().get(i).getName(), jsp);
}
this.endGameInfo.add(tabPane);
}
}
Snail source
share