そのため、GUI に GridBagLayout を使用していますが、サイズが適切に変更されないという問題が発生しています。誰かが別のレイアウトを提案する前に、私は GridBagLayout を使用したいと確信しています。多数のコンポーネントがあり、それらを適切にレイアウトしたいのですが、現在のコード/画像には、現在持っているものだけが表示されます。
とにかく、問題はそれ自体が適切にサイズ変更されないことです。サイズ変更時に現在のアスペクト比を維持したいのですが、そうではありません。特定のパネルには、サイズ変更時に何らかの優先順位が与えられているため、サイズ変更すると縦横比が乱れます。基本的に、いくつかのパネルが別のパネルよりも大きくなっていますが、サイズを変更すると、次のように別のパネルよりも小さくなります。
さて、私が実際に望んでいるのは、彼らがすでに示した比率を維持することです。ご覧のとおり、元のように、GUI のチャット部分を左側のパネルのいずれよりも小さくしたいと考えています。
以下は、これを生成するために現在持っているコードです。
jpPack = new JPanel();
jpCards = new JPanel();
jpInfo = new JPanel();
jpChat = new JPanel();
jpPack.setBackground(Color.red);
jpCards.setBackground(Color.blue);
jpInfo.setBackground(Color.green);
//create the Constraints and set some that will apply to each panel
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
//set the number of columns/rows to use
c.gridwidth = 1;
c.gridheight = 1;
//set the x and y position
c.gridx = 0;
c.gridy = 0;
//set the weight properties
c.weightx = 1.0;
c.weighty = 1.0;
getContentPane().add(jpCards, c);
//set the number of columns/rows to use
c.gridwidth = 1;
c.gridheight = 1;
//set the x and y position
c.gridx = 0;
c.gridy = 1;
//set the weight properties
c.weightx = 1.0;
c.weighty = 1.0;
getContentPane().add(jpPack, c);
//set the number of columns/rows to use
c.gridwidth = 1;
c.gridheight = 1;
//set the x and y position
c.gridx = 1;
c.gridy = 0;
//set the weight properties
c.weightx = 0.2;
c.weighty = 0.2;
getContentPane().add(jpInfo, c);
//set the number of columns/rows to use
c.gridwidth = 1;
c.gridheight = 1;
//set the x and y position
c.gridx = 1;
c.gridy = 1;
//set the weight properties
c.weightx = 0.2;
c.weighty = 0.2;
getContentPane().add(jpChat, c);
jpChat.setLayout(new GridLayout());
jpChat.add(client.gui.getContentPane(), c);
setVisible(true);
私がそれに取り組んでいる間、私は私が持っている他の質問をするかもしれません. GUI 全体とチャット パネルの両方に、最小サイズの制約を設定したいと考えています。まず、ユーザーが特定の x と特定の y よりも小さいサイズに変更できないようにしたい。後者の場合は、希望するアスペクト比を維持し、右側の 2 つのパネルの最小値に達した後、左側のパネルだけのサイズを変更します。つまり、あるサイズになるまで各パネルのサイズを変更してから、GUI 全体のサイズ変更を続けますが、左側のパネルのサイズを変更し、右側のパネルは最小サイズのままにします。
私を助けてくれてありがとう。これは本当に私を悩ませています.GridBagLayoutConstraintsをいじり、どこにも行きません. これは私が得た最高のものです。