Ich habe ein Problem einen JButton nach links auszurichten, ich habe 5 panels per BoxLayout ausgerichtet ( VERTICAL ) untereinander. Alle Inhalte ( Componenten) der Panels sind zentriert ***FEHLER*** genau, dies will ich nicht haben. Ich möchte das mein Button im letzen Panel ganz nach links ausgerichtet ist.
Ich habe es provisorisch mit GridBagLayout als Layout für Panel 5 gemacht ... jedoch bin ich nicht zufrieden.
Hier mein Code:
PANEL 5 ist das Problem
Ich habe es provisorisch mit GridBagLayout als Layout für Panel 5 gemacht ... jedoch bin ich nicht zufrieden.
Hier mein Code:
Code:
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Mancala extends JFrame {
public Mancala(){
super("Mancala Spielfeld");
init();
}
public void init() {
Container contentPane=getContentPane();
BoxLayout boxLayout=new BoxLayout(contentPane, BoxLayout.Y_AXIS);
contentPane.setLayout(boxLayout);
// Panel 1
JPanel ueberschrift=new JPanel();
FlowLayout flowLayout=new FlowLayout();
ueberschrift.setLayout(flowLayout);
JLabel label=new JLabel("Mancala");
ueberschrift.add(label);
contentPane.add(ueberschrift);
// Panel 2
JPanel eingabe=new JPanel();
eingabe.setLayout(flowLayout);
JLabel label1=new JLabel("Spieler 1:");
JTextField textfeld=new JTextField(20);
eingabe.add(label1);
eingabe.add(textfeld);
contentPane.add(eingabe);
// Panel 3
JPanel eingabe1=new JPanel();
eingabe1.setLayout(flowLayout);
JLabel label2=new JLabel("Spieler 2:");
JTextField textfeld1=new JTextField(20);
eingabe1.add(label2);
eingabe1.add(textfeld1);
contentPane.add(eingabe1);
// Panel 4
JPanel buttonpanel=new JPanel();
buttonpanel.setLayout(flowLayout);
JButton button1=new JButton("Los");
buttonpanel.add(button1);
contentPane.add(buttonpanel);
// Panel 5
JPanel buttonPanel2=new JPanel();
buttonPanel2.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
//GridBagConstraints c = new GridBagConstraints();
JButton button2=new JButton("Beenden");
//c.fill = GridBagConstraints.HORIZONTAL;
//c.ipady = 0; //reset to default
//c.weighty = 3.0; //request any extra vertical space
//c.anchor = GridBagConstraints.PAGE_END; //bottom of space
c.insets = new Insets(200,-180,20,0); //top padding
//c.gridx = 0; //aligned with button 2
//c.gridwidth = 2; //2 columns wide
//c.gridy = 2; //third row
buttonPanel2.add(button2,c);
contentPane.add(buttonPanel2,c);
}
}
PANEL 5 ist das Problem