Hallo Leute,
ich habe das Problem, dass zwischen manchen Panels, die ich zu meinem Frame mit GridLayout(6,1) hinzufüge, zu viel Abstand ist. Hier zu DIESER Screenshot. Mein Ziel ist es, den Platz um die roten Boxen zu entfernen...
Hier der Quelltext des Frames:
Letztendlich füge ich nur der Reihe nach sechs Panels zu dem Panel des Frames hinzu. Jedoch ist zwischen Panel1&2, 3&4 und 5&6 mehr Abstand, als zwischen 2&3 und 4&5...
Danke für Eure Hilfe.
Cya Moe
ich habe das Problem, dass zwischen manchen Panels, die ich zu meinem Frame mit GridLayout(6,1) hinzufüge, zu viel Abstand ist. Hier zu DIESER Screenshot. Mein Ziel ist es, den Platz um die roten Boxen zu entfernen...
Hier der Quelltext des Frames:
Code:
public class MainFrame extends JFrame {
private static final long serialVersionUID = -1L;
private static MainFrame INSTANCE = new MainFrame();
private final JRadioButton[] radioButtons = new JRadioButton[3];
private final JLabel ensureLabel, nextRepeatLabel;
private final JButton abort, button1, button2, switchButton;
private final JPanel cropPanel, fieldPanel;
private final JCheckBox[] fieldBoxes = new JCheckBox[6];
private final JComboBox cropBox, waterBonusBox;
private final JTextField repeatField;
private MainFrame() {
this.setTitle("MFF-Bot: The Next Generation");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(new GridLayout(6, 1));
JPanel welcomePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
welcomePanel.add(new JLabel(FinalVars.welcomeLabel));
this.add(welcomePanel);
JPanel plantSizePanel = new JPanel();
ButtonGroup bg = new ButtonGroup();
plantSizePanel.setLayout(new BoxLayout(plantSizePanel,
BoxLayout.PAGE_AXIS));
plantSizePanel.add(new JLabel(FinalVars.sizeQuestionLabel));
for (int i = 0; i < radioButtons.length; i++) {
radioButtons[i] = new JRadioButton(FinalVars.getRadioLabels(i));
bg.add(radioButtons[i]);
plantSizePanel.add(radioButtons[i]);
}
this.add(plantSizePanel);
radioButtons[2].setSelected(true);
cropPanel = new JPanel();
cropPanel.add(new JLabel("Plant"));
cropBox = new JComboBox(FinalVars.crops);
cropPanel.add(cropBox);
cropPanel.add(new JLabel("every"));
repeatField = new JTextField("-1");
repeatField.setHorizontalAlignment(JTextField.RIGHT);
repeatField.setColumns(3);
cropPanel.add(repeatField);
cropPanel.add(new JLabel("Minutes (Water-Bonus:"));
Long[] l = { Long.valueOf(5), Long.valueOf(10), Long.valueOf(15),
Long.valueOf(20), Long.valueOf(30) };
waterBonusBox = new JComboBox(l);
waterBonusBox.setSelectedIndex(1);
cropPanel.add(waterBonusBox);
cropPanel.add(new JLabel("%)"));
this.add(cropPanel);
fieldPanel = new JPanel(new GridLayout(2, 3));
for (int i = 0; i < fieldBoxes.length; i++) {
fieldBoxes[i] = new JCheckBox(FinalVars.fieldLabels[i], false);
fieldPanel.add(fieldBoxes[i]);
}
this.add(fieldPanel);
JPanel switchPanel = new JPanel();
ensureLabel = new JLabel();
ensureLabel.setLayout(new BoxLayout(ensureLabel, BoxLayout.LINE_AXIS));
switchPanel.add(ensureLabel);
switchButton = new JButton();
switchButton.addActionListener(new SwitchButtonListener());
switchPanel.add(switchButton);
this.add(switchPanel);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
buttonPanel.add(Box.createHorizontalGlue());
button1 = new JButton();
buttonPanel.add(button1);
buttonPanel.add(Box.createHorizontalStrut(10));
button2 = new JButton(FinalVars.button2Label);
buttonPanel.add(button2);
buttonPanel.add(Box.createHorizontalStrut(10));
nextRepeatLabel = new JLabel("");
buttonPanel.add(nextRepeatLabel);
abort = new JButton(FinalVars.abortLabel);
buttonPanel.add(abort);
buttonPanel.add(Box.createHorizontalStrut(10));
this.add(buttonPanel);
this.setVisible(true);
}
public static MainFrame getInstance() {
return INSTANCE;
}
}
Letztendlich füge ich nur der Reihe nach sechs Panels zu dem Panel des Frames hinzu. Jedoch ist zwischen Panel1&2, 3&4 und 5&6 mehr Abstand, als zwischen 2&3 und 4&5...
Danke für Eure Hilfe.
Cya Moe