Results 1 to 4 of 4
  1. #1
    glhansen is offline Member
    Join Date
    Mar 2009
    Posts
    20
    Rep Power
    0

    Default A few question about FlowLayout

    FlowLayout is easy to use and useful enough, but sometimes I want two things to remain associated with each other, like a label and a text field, and not split apart at the edge. I make a sub-panel, add the label and the text field to that, then add the sub-panel to my super-panel, and that seems to work fine. But is there an easier or better way?

    On the other hand, sometimes I want an item to appear on the next line, even if there's room for it on the line above. For that, I play tricks with a sub-panel with a BorderLayout or GridLayout or something. But it would be really nice if there was a "NewLine" object that tells FlowLayout to start a new line. Is there such a thing?

    Actually, it would be nice if FlowLayout had tab stops, too. It would be easy to line up buttons and fields without having to muck around with a GridBag or a bunch of sub-panels.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I usually nest layouts. For instance one way to have a column of x JLabels and a column of x matching JTextFields (and avoid GridBagLayout) is to put the labels in a JPanel (I call labelPanel) that uses GridLayout(0, 1, 0, 5) which stands for 1 column, 5 points between labels, and then put the JTextFields in a JPanel (I call fieldPanel) that uses the exact same layout. Then place the labelPanel BorderLayout.WEST into a JPanel that uses BorderLayout, and the fieldPanel BorderLayout.CENTER into the same BorderLayout panel. Play with it and have fun.
    Last edited by Fubarable; 03-23-2009 at 09:49 PM.

  3. #3
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    There's no single standard layout that'll do this. Solutions could be:
    - create a vertical Box, to which you add panels with FlowLayouts
    - create your own layout

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I've also heard good things about the MiG layout. It's not part of the Java core library, but some folks in this forum, the Sun fora, and JavaRanch Swing fora rave about it. I've never used it, but am thinking about trying it out. It can be found here: MiG Layout Java Layout Manager for Swing and SWT

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. Question!
    By anjogomez in forum Java Applets
    Replies: 2
    Last Post: 02-21-2009, 03:24 AM
  3. Hello everyone and my first question
    By htetnaing in forum New To Java
    Replies: 3
    Last Post: 01-26-2009, 03:49 PM
  4. New Line in FlowLayout
    By chris12295 in forum New To Java
    Replies: 1
    Last Post: 12-07-2007, 05:49 PM
  5. Help Using FlowLayout Manager
    By toad in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 12:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •