Results 1 to 5 of 5
- 08-04-2010, 08:55 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
group layout - link the size of components in different labels ?
Hi,
i have a gui in which has 5 panels (layed out from top to bottom in one column, using grouplayout).
now inside each of the panels it looks like this (they use grouplayout as well):
Java Code:label 1 component labelexample 2 component
however, the labels arent always the same size, e.g. the labels in panel 3 are 50% longer than the ones in panel 5
so all in all it looks like this:
Java Code:panel 1 ---------------------------------------------------------- label 1 component labelexample 2 component ---------------------------------------------------------- panel 2 ---------------------------------------------------------- label 1 component labelexample_takesmorespace 2 component ---------------------------------------------------------- panel 3 ---------------------------------------------------------- label 1 component label 2 component ---------------------------------------------------------- ... ...
I'd really like all the labels be the same size, so that the components all start at the same line. ive tried layout.linksize in the main frame, but this doesnt work, since the jlabels arent in a group in the main frame layout :( ( --> an exception is being thrown)
is there a way to do this? Any help apprechiated :)
- 08-04-2010, 01:38 PM #2
Define the size of one component in each panel and link it's size with others in same panel.
What I mean is :
That may work.Java Code:for panel1 label1.setSize(x,y); // then link with others of panel1. for panel2 label2.setSize(x,y); // then link with others of panel2.
-regardsLast edited by Prajin; 08-04-2010 at 01:43 PM.
- 08-04-2010, 08:59 PM #3
Earlier on another forum
Swing - grouplayout link size of components from different jpanels
db
- 08-05-2010, 07:45 AM #4
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
Thanks for your reply. Im going to try that. But this solution requires me to know the length of the longest label in use, right? Is there a way to guess that length already before the initiation of the gui components?
Originally Posted by prajin
- 08-05-2010, 08:08 AM #5
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
Ok, i got it now. Almost the way you suggested, prajin.
Here's how to do it:
Define a variable for the size of the longest label
Java Code:private Dimension labelSize = new Dimension(x,y);
Then for each panel:
Setting the minimum size of one of the labels used in that panel is enough
You dont have to use layout.linkSize. This would actually revert the effect and all labels will become "normal" again, if you have labels that are smaller than the "labelSize" dimensionJava Code:JLabel label1 = new JLabel("content"); label1.setMinimumSize(labelSize); JLabel label2 = .... JLabel ... ...
This way works fine, even though you have to know the size of the longest variable.
// im sorry for the crosspost, but i waited more than 2 weeks (in the other forum) and no one would help me, so i finally postet the question here as well. ill update the other thread as well.
Similar Threads
-
group layout - span ?
By random7 in forum AWT / SwingReplies: 4Last Post: 07-26-2010, 09:26 AM -
Help needed in layout of components
By silversurfer2in in forum AWT / SwingReplies: 2Last Post: 05-27-2010, 11:50 AM -
Components Layout in a JPanel
By jboy in forum New To JavaReplies: 4Last Post: 10-11-2009, 12:08 PM -
size och swt labels
By larsk in forum SWT / JFaceReplies: 0Last Post: 10-04-2009, 12:01 PM -
Layout problem / add components from another class
By ehochedez in forum AWT / SwingReplies: 9Last Post: 09-02-2009, 10:42 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks