Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Need Vertical Flow LayoutManager Advice

Thread view: 
John F. - 06 Dec 2005 21:00 GMT
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.
Thomas Hawtin - 06 Dec 2005 22:10 GMT
> 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
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Andrey Kuznetsov - 06 Dec 2005 22:36 GMT
>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
[quoted text clipped - 19 lines]
>
> I'd really appreciate some advice before I reinvent the wheel.

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

Signature

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 - 06 Dec 2005 22:42 GMT
> see http://jgui.imagero.com/rainLayout.html
> Hint - use  RainLayout.LAYOUT_POLICY_COMPUTE.

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

Signature

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

Roedy Green - 06 Dec 2005 23:35 GMT
>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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Andrey Kuznetsov - 07 Dec 2005 08:58 GMT
> 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.

Signature

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

John F. - 07 Dec 2005 13:51 GMT
Yes please, that would be a big help.  Thanks for the offer.
Andrey Kuznetsov - 07 Dec 2005 17:59 GMT
> Yes please, that would be a big help.  Thanks for the offer.

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

Signature

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 - 07 Dec 2005 17:59 GMT
> Yes please, that would be a big help.  Thanks for the offer.

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

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.