By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,129 Members | 2,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,129 IT Pros & Developers. It's quick & easy.

Layouts in Swings

100+
P: 184
Hi,
i need one small clarification in swing layouts.
I done coding as..

JPanel panel = new JPanel(new new GridLayout(5,0));
for(int i=0;i<5;i++)
{
panel.add(new JLabel("Label"+i));
panel.add(new JButton("button"+i))
}
(frame.getContentPane()).add(panel);
its working fine output is viewed in screen as
Label1 Button1
Label2 Button2
Label3 Button3
But what i need is
Label1 Button1
Label1 Button1
Label1 Button1
Button4 Button5 Button6

is it possible to add button4,button5,button6 in another panel and add to the frame?if not how it can be done. Thanks in Advance.

-Thanks &Regards,
Hamsa
Apr 3 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 10K+
P: 11,448
Hi,
i need one small clarification in swing layouts.
I done coding as..

JPanel panel = new JPanel(new new GridLayout(5,0));
for(int i=0;i<5;i++)
{
panel.add(new JLabel("Label"+i));
panel.add(new JButton("button"+i))
}
(frame.getContentPane()).add(panel);
its working fine output is viewed in screen as
Label1 Button1
Label2 Button2
Label3 Button3
But what i need is
Label1 Button1
Label1 Button1
Label1 Button1
Button4 Button5 Button6

is it possible to add button4,button5,button6 in another panel and add to the frame?if not how it can be done. Thanks in Advance.

-Thanks &Regards,
Hamsa
I suppose you mean:

Label1 Button1
Label2 Button2
Label3 Button3
Button4 Button5 Button6

The first three labels and buttons can be put in a JPanel A having a GridLayout(3, 0)
The second three Buttons can be put in another JPanel B having a GridLayout(1, 0)
Put both panels in a third JPanel C having a BorderLayout; put A in the CENTER
and put B south.

kind regards,

Jos
Apr 3 '08 #2

100+
P: 184
I suppose you mean:

Label1 Button1
Label2 Button2
Label3 Button3
Button4 Button5 Button6

The first three labels and buttons can be put in a JPanel A having a GridLayout(3, 0)
The second three Buttons can be put in another JPanel B having a GridLayout(1, 0)
Put both panels in a third JPanel C having a BorderLayout; put A in the CENTER
and put B south.

kind regards,

Jos
Thanks Jos, one more doubt i have..
i have the output screen with following button display..

Button1 Button2 Button3 Button4 Button5

But what i want is

Button1 Button2
Button3 Button4 Button5

where "Button3,Button4,Button5" needed to display in nextline..
How can i do that? Thanks in Advance.

-Thanks & Regards,
Hamsa
Apr 4 '08 #3

Expert 10K+
P: 11,448
Thanks Jos, one more doubt i have..
i have the output screen with following button display..

Button1 Button2 Button3 Button4 Button5

But what i want is

Button1 Button2
Button3 Button4 Button5

where "Button3,Button4,Button5" needed to display in nextline..
How can i do that? Thanks in Advance.

-Thanks & Regards,
Hamsa
What do you need all those funny layouts for? Have a look at the GridBagLayout
or the new SpringLayout layout managers. Also have a look at the invisible components
(that do take up space) that can be made by the Box class.

kind regards,

Jos
Apr 4 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.