Java アプリケーションの一部のコンポーネントのサイズ変更に問題があります。メインの JFrame のサイズを変更すると、周囲のコンポーネントを埋める代わりに、以前のサイズが維持されます。
たとえば、私のプログラムでは、別の JTabbedPane (メイン JFrame 内にある) のタブ内に JTabbedPane があります。内側の JTabbedPane に追加されたタブが、さまざまな .setPreferredSize() を介して周囲のスペース全体を埋めるようにします。次に、ウィンドウの隅をドラッグして JFrame のサイズを変更すると、外側の JTabbedPane のタブのサイズが正常に変更されますが、その中にある JTabbedPane は同じ古いサイズのままです。
JScrollPane でテストすると、同じことが起こります。外側の JTabbedPane は JScrollPane によってサイズ変更され、同じサイズのままです。
以下は、私が見逃した明らかな何かが見られる場合に備えて、タブ付きパネルを作成するためのコードです。JFrame のサイズが変更されたときにサイズが変更されないのは、createEndGamePane() の tabPane/jsp オブジェクトです。mainTabPane は必要に応じてサイズ変更されます。
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);;
//Create the gameTree
EndGameTreeCanvas gameTree = new EndGameTreeCanvas(e, this.endGameInfo.getSize());
//Create the ScrollPane
JScrollPane jsp = new JScrollPane(gameTree);
jsp.setPreferredSize(tabPane.getSize());
jsp.setBorder(BorderFactory.createEmptyBorder());
//Add to the endGameIndo panel
tabPane.addTab(this.tournament.data.getGroups().get(i).getName(), jsp);
}
this.endGameInfo.add(tabPane);
}
}