ahdgaudasdh p
ahdgaudasdh p

Reputation: 7

Borderlayout Gridlayout

public class Editor{

public static void main(String[] args) {
    JFrame f = new JFrame("Editpr");
    f.setLayout(new GridLayout(5, 2, 25, 54));

    JButton button1 = new JButton("1");     
    JButton button1 = new JButton("10");

    JTextArea ausgabe = new JTextArea();
    ausgabe.setText("Text");
    ausgabe.setEditable(false);

    f.add(ausgabe);
    f.add(button1);
    f.add(Button2)

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(550, 550);
    f.setVisible(true);

}

I need help with this Code. I want this is the grid layout in a Border Layout . The buttons to the center. Textarea should be in BorderLayout below. Who can help a newbie.

Upvotes: 0

Views: 7264

Answers (1)

Arnaud
Arnaud

Reputation: 17524

Here is an example of a panel with GridLayout, at the center of a panel with BorderLayout , and a text area to the south.

Note that I added random buttons to fill the grid, since your GridLayout has 5 rows and 2 columns (You probably planned to add some more components).

public static void main(final String[] args) {
    JFrame f = new JFrame("Editpr");

    JPanel content = new JPanel();
    content.setLayout(new BorderLayout());

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(5, 2, 25, 54));

    JButton button1 = new JButton("1");
    JButton button2 = new JButton("2");

    buttonsPanel.add(button1);
    buttonsPanel.add(button2);

    // random filling to demonstrate the result of the filled grid
    buttonsPanel.add(new JButton("3"));
    buttonsPanel.add(new JButton("4"));
    buttonsPanel.add(new JButton("5"));
    buttonsPanel.add(new JButton("6"));
    buttonsPanel.add(new JButton("7"));
    buttonsPanel.add(new JButton("8"));
    buttonsPanel.add(new JButton("9"));
    buttonsPanel.add(new JButton("10"));

    JTextArea ausgabe = new JTextArea();
    ausgabe.setText("Text");
    ausgabe.setEditable(false);

    content.add(buttonsPanel, BorderLayout.CENTER);
    content.add(ausgabe, BorderLayout.SOUTH);

    f.setContentPane(content);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(550, 550);
    f.setVisible(true);

}

Upvotes: 2

Related Questions