Learning Java
Learning Java

Reputation: 53

Setting boundaries for JPanel

I am new on using Swings

my requirement is to align components within the jpanel(panel2)

I have taken 2 JPanels (panel1, panel2) and added to the jframe

panel1.add(panel2);

panel2.setLayout(new flowLayout()); 

panel2.setBounds(80,120,100,100);

getContentPane() .add(Panel1);

and I have created a "Create" button that will generate text area dynamically in panel2

now my problem is if the created textarea is reaching out of panel2 it has to show an error message "You reached the boundaries of the jpanel so the textarea cant be created "

Thanks in advance

Upvotes: 0

Views: 2129

Answers (1)

Audrius Meškauskas
Audrius Meškauskas

Reputation: 21728

Set the layout before you add any elements to the panel. No not call setBounds as with layout manager present it likely has no effect at all.

I cannot explain how to layout your elements as from your question seems not possible to figure out that do you want to do. Best, post the drawing with elements as they should look like. GridLayout maybe would be good if you want to align multiple elements as in the table.

Upvotes: 1

Related Questions