dcsimg
using multiple layout managers
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   monica_shrivastava
Posted On:   Friday, June 9, 2006 05:55 AM


if i want to use multiple layout managers n one frame how can i do it? can i add different panels and have different layout managers for each one of them?
plz can u mail me an example of such a program with a code too.

Re: using multiple layout managers

Posted By:   Robert_Lybarger  
Posted On:   Friday, June 9, 2006 07:12 AM

Yes... your frame can have multiple panels as its children, and each panel can independently have layout managed by separate types of managers. what follows is just a crude example...




//somewhere in the frame's layout code, where
//the frame has borderlayout running...

Panel p1 = new Panel();
p1.setLayout(new FlowLayout());
p1.add(new JLabel("Foo"));
p2.add(new JLabel("Bar"));

Panel p2 = new Panel();
p2.setLayout(new GridLayout(1,2));
p2.add(new JLabel("One");
p2.add(new JLabel("Two");

this.add(p1, "Center");
this.add(p2, "South");

// etc

Re: using multiple layout managers

Posted By:   Jani_Kaarela  
Posted On:   Friday, June 9, 2006 06:25 AM


IIRC, any Container can have a separate layout manager. Since Panel is a subclass of Container, each Panel can have it's own layout manager.



Learn to use the API docs.

About | Sitemap | Contact