私はこのような JPanel を持っています:
GridBagConstraints constPanelInfo = new GridBagConstraints();
panelInfo = new JPanel(new GridBagLayout());
JLabel sensor1 = new JLabel("Sensor: ");
constPanelInfo.gridx = 0;
constPanelInfo.gridy = 0;
constPanelInfo.weightx = 0.0;
constPanelInfo.fill = GridBagConstraints.NONE;
panelInfo.add(sensor1, constPanelInfo);
constPanelInfo.gridx = 1;
constPanelInfo.gridy = 0;
constPanelInfo.weightx = 1.0;
constPanelInfo.fill = GridBagConstraints.HORIZONTAL;
campoSensor.setPreferredSize(new Dimension(100, campoSensor.getPreferredSize().height));
panelInfo.add(campoSensor, constPanelInfo);
ここで、campoSensor は次のように定義されます。
private JTextField campoSensor = new JTextField();
...しかし、JTextField は、必要に応じて 100 ピクセルの重みにスケーリングされません。setPreferredSize メソッドを書き込む前と同じサイズのままです。ここにアイデアはありますか?