Positioning child panels using FlowLayout

Posted by extro on Stack Overflow See other posts from Stack Overflow or by extro
Published on 2010-03-29T17:38:41Z Indexed on 2010/03/29 17:53 UTC
Read the original article Hit count: 116

Filed under:
|

I have two panels:

  • main_panel
  • child_panel

The main_panel layout is set using:

main_panel.setLayout(flowlayout)

I then added child_panel to main_panel:

main_panel.add(child_panel)

The child_panel gets added to main_panel but its position is at the cross-section of horizontal midpoint and top vertical section of screen. I want child_panel to be at the top left corner, something I could have done by using child_panel.setlocation(a,b) method, if I have set the layout of main_panel as null.

I have used FlowLayout here because I want components in the JPanel to keep adjusting with the size of JFrame.

So can I add child_panel to main_panel at the exact location I want, even if I set the Layout of main_panel as not null?

© Stack Overflow or respective owner

Related posts about java

Related posts about swing