Need Vertical Flow LayoutManager Advice

Discussion in 'Java' started by John F., Dec 6, 2005.

  1. John F.

    John F. Guest

    I need to fill a JPanel container with an array of smaller, square
    JPanels. They need to flow vertically down a column until they reach
    the bottom of the JPanel container then start again in a new column
    immediately to the right. I'll not know how many smaller JPanels I
    will use until I query a database (they are contacts goint into a
    contact list grid.)

    For instance, if there were 22 smaller panels:
    1 6 11 16 21
    2 7 12 17 22
    3 8 13 18
    4 9 14 19
    5 10 15 20

    Preferably, if the container were to be resized where the height was
    less, then a row would be subtracted off and a new column created:

    1 5 9 13 17 21
    2 6 10 14 18 22
    3 7 11 15 19
    4 8 12 16 20

    I'd really appreciate some advice before I reinvent the wheel.
    John F., Dec 6, 2005
    #1
    1. Advertising

  2. John F. wrote:
    > I need to fill a JPanel container with an array of smaller, square
    > JPanels. They need to flow vertically down a column until they reach
    > the bottom of the JPanel container then start again in a new column
    > immediately to the right. I'll not know how many smaller JPanels I
    > will use until I query a database (they are contacts goint into a
    > contact list grid.)


    Perhaps the simplest hack is to use GridLayout with a ComponentListener
    that sets the number of rows and columns on componentResized.

    Simple layout managers aren't that hard to write. There may be some open
    source solution somewhere, but that might be more hassle than it's worth.

    JList with setLayoutOrientation(JList.VERTICAL_WRAP) may be enough to
    meet your needs.

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Dec 6, 2005
    #2
    1. Advertising

  3. >I need to fill a JPanel container with an array of smaller, square
    > JPanels. They need to flow vertically down a column until they reach
    > the bottom of the JPanel container then start again in a new column
    > immediately to the right. I'll not know how many smaller JPanels I
    > will use until I query a database (they are contacts goint into a
    > contact list grid.)
    >
    > For instance, if there were 22 smaller panels:
    > 1 6 11 16 21
    > 2 7 12 17 22
    > 3 8 13 18
    > 4 9 14 19
    > 5 10 15 20
    >
    > Preferably, if the container were to be resized where the height was
    > less, then a row would be subtracted off and a new column created:
    >
    > 1 5 9 13 17 21
    > 2 6 10 14 18 22
    > 3 7 11 15 19
    > 4 8 12 16 20
    >
    > I'd really appreciate some advice before I reinvent the wheel.


    see http://jgui.imagero.com/rainLayout.html
    Hint - use RainLayout.LAYOUT_POLICY_COMPUTE.

    --
    Andrey Kuznetsov
    http://uio.imagero.com Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
    Andrey Kuznetsov, Dec 6, 2005
    #3
  4. Andrey Kuznetsov, Dec 6, 2005
    #4
  5. John F.

    Roedy Green Guest

    On 6 Dec 2005 13:00:13 -0800, "John F." <> wrote,
    quoted or indirectly quoted someone who said :

    >I need to fill a JPanel container with an array of smaller, square
    >JPanels.


    instead of an array of JPanels, two other approaches are a JTable and
    a overriding paintComponent and using drawString to do the work.

    I think you will find drawString at least an order of magnitude
    faster, and probably even simpler than the other two approaches.

    The big problem with it is there is no built in select/copy/paste.

    see http://mindprod.com/jgloss/canvas.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Dec 6, 2005
    #5
  6. > instead of an array of JPanels, two other approaches are a JTable

    BTW I wrote once LinearTableModel which makes exactly what you need -
    it looks at component width and changes column count.
    If you need I can send you source.

    --
    Andrey Kuznetsov
    http://uio.imagero.com Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
    Andrey Kuznetsov, Dec 7, 2005
    #6
  7. John F.

    John F. Guest

    Yes please, that would be a big help. Thanks for the offer.
    John F., Dec 7, 2005
    #7
  8. Andrey Kuznetsov, Dec 7, 2005
    #8
  9. Andrey Kuznetsov, Dec 7, 2005
    #9
    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. Replies:
    1
    Views:
    398
  2. Buck Rogers

    Need help understanding program control/flow.

    Buck Rogers, May 10, 2006, in forum: C Programming
    Replies:
    7
    Views:
    260
    void * clvrmnky()
    May 10, 2006
  3. Jack Dowson
    Replies:
    0
    Views:
    448
    Jack Dowson
    May 7, 2007
  4. Sam Takoy

    Custom LayoutManager troubles

    Sam Takoy, Apr 5, 2010, in forum: Java
    Replies:
    4
    Views:
    304
    markspace
    Apr 5, 2010
  5. Matthew
    Replies:
    3
    Views:
    83
    Matthew
    Feb 10, 2004
Loading...

Share This Page