Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Need Vertical Flow LayoutManager Advice

Reply
Thread Tools

Need Vertical Flow LayoutManager Advice

 
 
John F.
Guest
Posts: n/a
 
      12-06-2005
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.

 
Reply With Quote
 
 
 
 
Thomas Hawtin
Guest
Posts: n/a
 
      12-06-2005
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/
 
Reply With Quote
 
 
 
 
Andrey Kuznetsov
Guest
Posts: n/a
 
      12-06-2005
>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


 
Reply With Quote
 
Andrey Kuznetsov
Guest
Posts: n/a
 
      12-06-2005
> see http://jgui.imagero.com/rainLayout.html
> Hint - use RainLayout.LAYOUT_POLICY_COMPUTE.


sorry for wrong hint - RainLayout.LAYOUT_POLICY_ASK is right one!

--
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


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-06-2005
On 6 Dec 2005 13:00:13 -0800, "John F." <(E-Mail Removed)> 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.
 
Reply With Quote
 
Andrey Kuznetsov
Guest
Posts: n/a
 
      12-07-2005
> 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


 
Reply With Quote
 
John F.
Guest
Posts: n/a
 
      12-07-2005
Yes please, that would be a big help. Thanks for the offer.

 
Reply With Quote
 
Andrey Kuznetsov
Guest
Posts: n/a
 
      12-07-2005
> Yes please, that would be a big help. Thanks for the offer.

download here: http://www.imagero.com/table.zip

--
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



 
Reply With Quote
 
Andrey Kuznetsov
Guest
Posts: n/a
 
      12-07-2005
> Yes please, that would be a big help. Thanks for the offer.

download here: http://www.imagero.com/table.zip

--
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



 
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
Custom LayoutManager troubles Sam Takoy Java 4 04-05-2010 08:11 PM
Query:difference between node flow and filter flow in java's I/O,system? Jack Dowson Java 0 05-07-2007 03:35 PM
Swing Printing and LayoutManager carl.manaster@gmail.com Java 1 05-22-2006 09:14 PM
Re: I Need a " very simple flow chart program" Boomer Computer Support 0 07-31-2003 05:39 AM
I need a very basic flow chart program Watcher@the.gate Computer Support 3 07-30-2003 01:42 AM



Advertisments