Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 22nd, 2005, 01:48 PM
Registered User
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default JPanel components on same line

I am using a swing JPanel, with the standard flow layout. I have 3 components in the panel; JLabel, JTextField and JButton.
I want to have it so I have the JLabel on its own line, then the JTextField and JButton next to each other on the next line.

A BorderLayout does not work because it seems you cant have two components in the same (CENTER) area.
A box layout does not work because it puts all 3 on a separate lines.

Is a GridBagLayout the only way to achieve this?

cheers!
 
Old May 28th, 2005, 02:53 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Put the JTextField and JButton into another JPanel and add the (sub)JPanel and the JButton to the main JPanel?

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com
 
Old September 1st, 2005, 06:18 PM
Authorized User
 
Join Date: Jul 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to merediths
Default


disclaimer, i didn't check any of the syntax, so just use this as a concept -- dont try to copy and paste the code:

Box hBox = Box.createHorizontalBox();
Box vBox = Box.createVerticalBox();

hBox.add(new JTextField("blah"));
hBox.add (new JButton("Click Me"));

vBox.add(new JLabel("enter Blah"));
vBox.add(hBox);

you get something like


-----------
| 1 | <--- vertical box
| |
|-------- |
| | |
| 2 | 3 | <--- horizontal box nested in vBox
-----------

ciderpunx suggestion works too -- I like to do it this way so I don't have to create a lot of other classes. But I have some background in web stuff / using tables for layout so I'm used to thinking in that way -- if you're not, that solution may seem a bit stilted and hard to use to you; in that case, go with the sub-JPanels.


Regards,
Meredith Shaebanyan






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to draw indicator line in owc line chart AlexOo General .NET 0 July 9th, 2007 10:32 PM
How to paste a bitmap into a JPanel? AndrewH Java GUI 1 May 1st, 2007 12:19 AM
How to read file line by line in EVC++ iriskab Visual C++ 0 September 27th, 2006 01:39 PM
Reading line by line from a .txt file x_ray VB.NET 2002/2003 Basics 5 February 10th, 2006 01:55 PM
Can I add a JComboBox twice to the same jpanel david.byrne Java GUI 4 May 14th, 2005 11:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.