Simple GridBagLayout Question

Discussion in 'Java' started by AJ, Jun 10, 2004.

  1. AJ

    AJ Guest

    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
     
    AJ, Jun 10, 2004
    #1
    1. Advertising

  2. 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
     
    Andrew Thompson, Jun 10, 2004
    #2
    1. Advertising

  3. AJ

    Johan Poppe Guest

    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 >
     
    Johan Poppe, Jun 10, 2004
    #3
  4. AJ

    Hal Rosser Guest

    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" <> wrote in message
    news:...
    > 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
     
    Hal Rosser, Jun 11, 2004
    #4
  5. 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
     
    Andrew Thompson, Jun 11, 2004
    #5
  6. AJ

    Sam Guest

    (AJ) wrote in message news:<>...
    > 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
     
    Sam, Jun 11, 2004
    #6
  7. AJ

    AJ Guest

    (AJ) wrote in message news:<>...
    > 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!
     
    AJ, Jun 14, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Passero

    grid or gridbaglayout

    Passero, Jul 2, 2003, in forum: Java
    Replies:
    3
    Views:
    3,111
    dhek bhun kho
    Jul 2, 2003
  2. me
    Replies:
    2
    Views:
    4,513
    Sudsy
    Jul 21, 2003
  3. MS
    Replies:
    0
    Views:
    457
  4. Daniel Tahin

    GridBagLayout question

    Daniel Tahin, Mar 27, 2005, in forum: Java
    Replies:
    14
    Views:
    708
    Daniel Tahin
    Apr 1, 2005
  5. Ulf Meinhardt
    Replies:
    13
    Views:
    1,338
    steve
    Apr 16, 2006
Loading...

Share This Page