aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Need suggestion reg Layout Managers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need suggestion reg Layout Managers" Watch "Need suggestion reg Layout Managers" New topic
Author

Need suggestion reg Layout Managers

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
I am generating set of JLabel and Checkboes on the fly dynamically in a JPanel.

JLabel1 chbk1 chbk2 chbk3 chbk4
JLabel2 chbk1 chbk2 chbk3 chbk4 chbk5 chbk6
...
..
.

And the list grows. Each set of JLabel followed by chbks are generated in one step. The number of checkboxes vary in each and every step.

All tehse elements are right now in a JPanel and unfortunately I couldn't figure out a proper layout manager for this scenario. Can any one suggest a solution.
[ April 10, 2008: Message edited by: Gopu Akraju ]
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
How about somewhat like this?



-mainPanel - BoxLayout wiht Y_Axis
[
[FlowLayout with Left alignment]
[FlowLayout with Left alignment]
[FlowLayout with Left alignment]
]
[ April 10, 2008: Message edited by: Edwin Dalorzo ]
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Thanks Edwin for the suggestion. Let me explain my scenario bit more clearly.
Every time I press a button, I will be displaying one label followed by few check boxes. The list grows when I press the button again. Every time I will get one label followed by few check boxes.

Does you logic still hold good in this situation? Infact with normal JPanel and FlowLayout, the list was growing perfectly fine and when I try putting the panel into a scrollable pan, all the components started growing horizontally in one single line with horizontal bar.

Let me try your logic for now as I have been running around the bush for few days without any solution. Thanks.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 863
    
    1
Originally posted by Gopu Akraju:
Thanks Edwin for the suggestion. Let me explain my scenario bit more clearly.
Every time I press a button, I will be displaying one label followed by few check boxes. The list grows when I press the button again. Every time I will get one label followed by few check boxes.

Does you logic still hold good in this situation? Infact with normal JPanel and FlowLayout, the list was growing perfectly fine and when I try putting the panel into a scrollable pan, all the components started growing horizontally in one single line with horizontal bar.


Yes, his suggestion is still valid in this situation. He's using one FlowLayout
per set, and you want each set "growing horizontally in one single line," right?

btw, it's good you described your requirements better, but is there a
reason you started a new thread instead of continuing with the old one?

[edit: Now that I understand that the number of Components in each row
will vary, I withdraw my previous suggestion to use GridLayout(0, N).]
[ April 10, 2008: Message edited by: Brian Cole ]

bitguru blog
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
yes you are right. Instead of running around the bush again, I thought let me explain my problem from the scratch and get someone's suggestion. Hence. started a new thread. Let me try it and get back to you all. Thanks.
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
The logic works fine. Every set of components are added in signle line. Again I am back to square problem. If I start using scrollable pane, the components are added in one single horizontal line with horizontal bar? Is there any trick to over write this?
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 863
    
    1
Originally posted by Gopu Akraju:
Instead of running around the bush again, I thought let me explain my problem from the scratch and get someone's suggestion. Hence. started a new thread.


Explaining your problem from scratch is good (in fact, perhaps you
should do so again, see below) but there was no reason to start a
new thread.

The logic works fine. Every set of components are added in signle line. Again I am back to square problem. If I start using scrollable pane, the components are added in one single horizontal line with horizontal bar?


From your description I thought you wanted each set to be in a single line that would scroll if it got too wide. If not, please explain what you are looking for.

If you want each set to wrap, you could use GridLayout(GridLayout(0, N))
for each set's panel, but you would have to hard-code the N (and also it wouldn't play very nice with an enclosing scroll pane). If you want them to wrap dynamically you could try Mr. Prime's JViewportFlowLayout that he helpfully provided in your previous thread on this topic.
[ April 11, 2008: Message edited by: Brian Cole ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need suggestion reg Layout Managers