Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Simple GridBagLayout Question

Reply
Thread Tools

Simple GridBagLayout Question

 
 
AJ
Guest
Posts: n/a
 
      06-10-2004
Obviously not simple to me, otherwise I wouldn't be here. But maybe
simple for you. I have a JPanel with a GridBagLayout. This JPanel
should have 2 columns and 2 rows. I would like to ensure that the two
columns always remain the same width, no matter their contents. How
can I do this? As it stands now, if I have text in one, and nothing
in the other column, the column with text is wider than the other one.
However, when they both contain equal text, or both are empty, they
are the same width, which is what I want. Thanks a lot!

AJ
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      06-10-2004
On 10 Jun 2004 10:42:15 -0700, AJ wrote:

> ...I have a JPanel with a GridBagLayout.


<http://www.physci.org/codes/javafaq.jsp#cljg>

>..This JPanel
> should have 2 columns and 2 rows. I would like to ensure that the two
> columns always remain the same width, no matter their contents.


Use a GridLayout for the columns.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
 
Johan Poppe
Guest
Posts: n/a
 
      06-10-2004
AJ skrev:

>Obviously not simple to me, otherwise I wouldn't be here. But maybe
>simple for you.


Nothing is "simple" with GridBagLayout.

>I have a JPanel with a GridBagLayout. This JPanel
>should have 2 columns and 2 rows. I would like to ensure that the two
>columns always remain the same width, no matter their contents.


I don't think you can do that with a GridBagLayout. (At least, I can't
think of a way.) But you can instead use two 2x1 GridLayouts and a
vertical Box.

--
Riktig sitering gjør meldingene dine lettere å lese:
< url: http://home.online.no/~vidaandr/news/OBSquoting.html >
 
Reply With Quote
 
Hal Rosser
Guest
Posts: n/a
 
      06-11-2004
I ran into this - had to put something in each grid position. In my case, I
put an empty label.
You could put a panel in each position - set the size of each - and put your
components on the panels - kinda messy.


"AJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Obviously not simple to me, otherwise I wouldn't be here. But maybe
> simple for you. I have a JPanel with a GridBagLayout. This JPanel
> should have 2 columns and 2 rows. I would like to ensure that the two
> columns always remain the same width, no matter their contents. How
> can I do this? As it stands now, if I have text in one, and nothing
> in the other column, the column with text is wider than the other one.
> However, when they both contain equal text, or both are empty, they
> are the same width, which is what I want. Thanks a lot!
>
> AJ



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 5/22/2004


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-11-2004
On Thu, 10 Jun 2004 22:37:19 -0400, Hal Rosser wrote:

> You could put a panel in each position - set the size of each - and put your
> components on the panels - kinda messy.


That would render this broken
layout even more broken.

Explicitly setting sizes of components
is generally a sign you need to rework
the GUI, ..or scrap it and start over.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
Sam
Guest
Posts: n/a
 
      06-11-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (AJ) wrote in message news:<(E-Mail Removed). com>...
> Obviously not simple to me, otherwise I wouldn't be here. But maybe
> simple for you. I have a JPanel with a GridBagLayout. This JPanel
> should have 2 columns and 2 rows. I would like to ensure that the two
> columns always remain the same width, no matter their contents. How
> can I do this? As it stands now, if I have text in one, and nothing
> in the other column, the column with text is wider than the other one.
> However, when they both contain equal text, or both are empty, they
> are the same width, which is what I want. Thanks a lot!
>
> AJ


I would use a Border layout with JSplitPane in the center, divided
vertically, with a JTextArea contained in either side. You can set the
width of the JSplitPane, or just take the default. A benefit to this
approach is that the user can decide on the sizing of the columns,
instead of the omniscient developer.

Sam90
 
Reply With Quote
 
AJ
Guest
Posts: n/a
 
      06-14-2004
(E-Mail Removed) (AJ) wrote in message news:<(E-Mail Removed). com>...
> Obviously not simple to me, otherwise I wouldn't be here. But maybe
> simple for you. I have a JPanel with a GridBagLayout. This JPanel
> should have 2 columns and 2 rows. I would like to ensure that the two
> columns always remain the same width, no matter their contents. How
> can I do this? As it stands now, if I have text in one, and nothing
> in the other column, the column with text is wider than the other one.
> However, when they both contain equal text, or both are empty, they
> are the same width, which is what I want. Thanks a lot!
>
> AJ



I ended up changing my 2x2 layout to a 1x2 layout, since the first row
were just labels describing the contents of the second row. So I gave
the elements in the second row (JTextAreas) titled borders, and
arranged it in a 1x2 GridLayout. It looks and works SO much better,
and it is about 1/4 the code to boot! Thanks for the suggestions!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridBagLayout question: Position 3 and 2 equal sized buttons problem ? Ulf Meinhardt Java 13 04-16-2006 09:41 PM
GridBagLayout question Daniel Tahin Java 14 04-01-2005 12:17 PM
recommend group or forum for netbeans gridbaglayout editor question. MS Java 0 02-15-2005 02:50 PM
GridBagLayout and JTextField me Java 2 07-21-2003 02:59 PM
grid or gridbaglayout Passero Java 3 07-02-2003 09:21 PM



Advertisments