Sthatyc Soul. Sthatyc Soul. - 7 months ago 32
Java Question

Put a JTextArea in specific location

I want to know, how can I put my

, down of some buttons I have in my program... To show you how I want to order this, I made an example in a GUI.

Image example:

enter image description here

Basically, I want to put them down of the buttons, like in the example.
I try to put a JPanel as flowlayout, and add the JTextArea, but dont works.


Here is an example, as suggested a BorderLayoutis appropriate for the main panel.

To be the closer possible to your example, I added a margin (an empty border) to the north panel, as well as a horizontal strut between the buttons (with the use of a BoxLayoutfor the north panel).

JFrame frame = new JFrame();

JPanel contentPanel = new JPanel();

contentPanel.setLayout(new BorderLayout());

JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
buttonsPanel.setBorder(new EmptyBorder(10, 10, 10, 10));

JButton b1 = new JButton("B1");
JButton b2 = new JButton("B2");


contentPanel.add(buttonsPanel, BorderLayout.NORTH);
contentPanel.add(new JTextArea(), BorderLayout.CENTER);

frame.setSize(400, 300);