プログラムでパネルをセットアップしようとしていますが、GridBagLayout の予想される動作と思われるものを取得できません (もちろん正しいです、GIGO)。ページの一部のコンポーネントのサイズを変更したいと思います。
セットアップ方法は 2 つの部分に分かれています。
1. マネージャー ペイン内のコンテンツ ペイン:
myPlayerContentPane =
new PlayerContentPane(myEventListener);
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty =1;
this.add(myPlayerContentPane,c);
myPlayerContentPane.setBorder(BorderFactory.createLineBorder(Color.black));
フレームのサイズを変更すると、このサブペインが拡大するはずですよね?これは、weight コマンドと fill コマンドによるものです。
2. コンテンツ ペインの内容:
setLayout(new GridBagLayout());
c.insets = new Insets(1, 1, 1, 1);
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.HORIZONTAL;
this.add(newCharacterButton,c);
newCharacterButton.addActionListener(new ActionListener(){
...
});
c.gridx = 1;
c.gridy = 0;
c.gridheight = 1;
c.fill = GridBagConstraints.HORIZONTAL;
this.add(newCharacterName,c);
c.gridx = 0;
c.gridy = 1;
c.fill = GridBagConstraints.HORIZONTAL;
this.add(loadCharacterButton,c);
loadCharacterButton.addActionListener(new ActionListener() {
...
});
c.gridx = 2;
c.gridy = 0;
c.fill = GridBagConstraints.HORIZONTAL;
this.add(editCharacterButton,c);
c.gridx = 2;
c.gridy = 1;
c.fill = GridBagConstraints.HORIZONTAL;
this.add(deleteCharacterButton,c);
deleteCharacterButton.addActionListener(new ActionListener(){
...
});
c.gridx = 2;
c.gridy = 2;
c.fill = GridBagConstraints.BOTH;
c.gridheight = 3;
c.ipady = 200;
c.weighty = 1;
this.add(characterListScroller,c);
c.gridx = 0;
c.gridy = 4;
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 2;
c.ipady = 200;
c.weighty =1;
this.add(characterSummaryScroller,c);
これで、プログラムが読み込まれると問題なく表示され、サイズ変更時に 2 つの JScrollPanes のサイズが変更されることを期待しています。ただし、コードで優先サイズを設定するすべてのインスタンスを削除しても (フレーム自体であっても) 、サイズ変更の動作は見られません。
以下は、プログラムが最初にロードされたときの設定で、最小サイズにスナップされています。
そして、フレームのサイズを変更したところ、パネルがそれに追随しませんでした。
現在、マネージャー ペインはCardLayout を含むフレーム内にあり、確認したところ、フレームに合わせてサイズが変更されません。これがトップ レベルのペインです (私が設定しました)。すべてのサイズを変更するにはどうすればよいですか?