我在 SWING 中编写一个 gui:
JLabel tLabel1 = new JLabel("Name: ");
JFormattedTextField tTextField1 = new JFormattedTextField();
textBoxes.add(tTextField1);
JLabel tLabel2 = new JLabel("Maximaler Preis: ");
JFormattedTextField tTextField2 = new JFormattedTextField();
textBoxes.add(tTextField2);
GridBagLayout tLayout = new GridBagLayout();
mainFrame.getContentPane().setLayout(tLayout);
// tLayout).setAutoCreateGaps(true);
// tLayout.setAutoCreateContainerGaps(true);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.anchor = GridBagConstraints.WEST;
mainFrame.add(new JLabel("Geben sie bitte die Kriterien für die Suche an:"), gbc);
gbc.gridwidth = 1;
gbc.gridy++;
mainFrame.add(tLabel1, gbc);
gbc.gridy++;
mainFrame.add(tLabel2, gbc);
gbc.gridy++;
mainFrame.add(tLabel3, gbc);
gbc.gridy++;
mainFrame.add(tLabel4, gbc);
gbc.gridx++;
gbc.gridy = 1;
mainFrame.add(tTextField1, gbc);
gbc.gridy++;
mainFrame.add(tTextField2, gbc);
gbc.gridy++;
mainFrame.add(tTextField3, gbc);
gbc.gridy++;
mainFrame.add(tCombo, gbc);
gbc.gridy++;
mainFrame.add(searchButton, gbc);
gbc.gridy++;
gbc.gridx = 0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainFrame.add(tTable, gbc);
mainFrame.setSize(800, 500);
mainFrame.pack();
我的文本字段如下所示:
|
如何在 GridBagLayout 中给它们一个宽度?