Ich habe in ein ziemlich nerviges Problem gerannt. Das JPanel fügt eine vertikale Lücke zwischen Komponenten hinzu, und ich muss das loswerden. Ich versuche, diese zu erhalten (blaue Linien sind der Raum Ich möchte loswerden):Java, wie JPanel Komponenten automatische vertikale Größenänderung deaktivieren
Um wie folgt aussehen:
Hier ist meine aktuelle Klasse ist :
public class SummaryPanel extends JPanel
{
private JLabel bagelLabel;
private JLabel toppingLabel;
private JLabel coffeeLabel;
private JLabel shotsLabel;
private JLabel subtotal;
private JLabel tax;
private JLabel total;
private JPanel selectionsPanel;
private JPanel totalPanel;
public SummaryPanel()
{
bagelLabel = new JLabel("No bagel $0.00");
toppingLabel = new JLabel("No topping $0.00");
coffeeLabel = new JLabel("No coffee $0.00");
shotsLabel = new JLabel("(Includes 0 shots) $0.00");
subtotal = new JLabel("");
tax = new JLabel("");
total = new JLabel("");
setLayout(new GridLayout(2,1));
selectionsPanel = new JPanel();
selectionsPanel.setLayout(new GridLayout(4,1));
selectionsPanel.add(bagelLabel);
selectionsPanel.add(toppingLabel);
selectionsPanel.add(coffeeLabel);
selectionsPanel.add(shotsLabel);
totalPanel = new JPanel();
totalPanel.setLayout(new GridLayout(3,1));
totalPanel.add(subtotal);
totalPanel.add(tax);
totalPanel.add(total);
totalPanel.setVisible(false);
add(selectionsPanel);
add(totalPanel);
}
}