chaning label sizes during runtime  
Author Message
Daniel





PostPosted: 2005-10-17 13:45:00 Top

java-programmer, chaning label sizes during runtime hi all,
I have a minor problem in my application (sorry I can't post any code,
so I'vm only asking for guidance in the general case, not this
specific one).
In my application I have a number of JLabels that gets their texts
changed during runtime. Unfortunatley it seems that they sometimes
become too wide for the panel they are in. The panel has room to grow
though (it is located in a jscrollpane).
I use
label.invalidate();
after each change, and
validateTree();
on the top container after all changes.
This gives me a somewhat strange behavour though.
On first run nothing happens (i.e the label get's cut)
on second run, the panel to the left shrinks a bit and the lables
there get's cut. On the third run all looks nice.
(run means updating of the labels, not a re-run of the application)

So what is the best way to handle this?
Should I invalidate, and revalidate myself? and if so when should that
be done?
All changes to components are executed in the EDT.

regards
Daniel
 
Roedy Green





PostPosted: 2005-10-17 16:34:00 Top

java-programmer >> chaning label sizes during runtime On Mon, 17 Oct 2005 05:44:35 GMT, Daniel
<email***@***.com> wrote or quoted :

>validateTree();

Try plain validate and see if it makes any difference. Keep in mind
validate does not change the size of the container validated. Use pack
if you want it to change size to minimally fit everything.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Daniel





PostPosted: 2005-10-18 7:40:00 Top

java-programmer >> chaning label sizes during runtime >Try plain validate and see if it makes any difference. Keep in mind
>validate does not change the size of the container validated. Use pack
>if you want it to change size to minimally fit everything.

hmm, pack is only available on the Window and I can not use it on my
panel, my whole window is in a size larger than my panel anyway, plus
it is not suitable to change the window size. My panel has lots of
room to grow. I will during the day try to make a small compilable
example of my problem. To show what problem I have. I can hopefully
reproduce it.

regards
Daniel

 
 
Daniel





PostPosted: 2005-10-18 10:58:00 Top

java-programmer >> chaning label sizes during runtime I have while I tried to make a small compilable example came to the
conclusion that it is the layout manager that is the problem.
I use SpringLayout and SUN's SpringUtilities.

So this leads to two solution paths
1. Figure out how to convince SpringLayout to grow the container
2. Use a different LayoutManager.

On note two..
my layout consists of a label and to the right of the label an image
(that indicates the state of a relay). I have approx 11 of these
pairs, in of course, 11 rows.
I want the label to be left justified, and the image to be right
justified. So any extra space given by a shorter name on any relay
ends up between the text and the image.
SpringLayout does this job very neatly, except for above mentioned
problems.
Any suggestions for any other layoutmanagers that may handle this
better?

regards
Daniel

 
 
Roedy Green





PostPosted: 2005-10-18 14:03:00 Top

java-programmer >> chaning label sizes during runtime On Mon, 17 Oct 2005 23:40:13 GMT, Daniel
<email***@***.com> wrote or quoted :

>My panel has lots of
>room to grow.

If you expect the panel to change size, you are going to have to
invalidate/validate ITS container.

If you are not familiar with how layouts work, you might try reading
http://mindprod.com/jgloss/layout.html

then you can instrument your various getPreferredSize getMiniumSize
getMaxiumSize and setSize methods (or just watch them in a debugger)
to figure out why the layout is behaving the way it is.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
 
Roedy Green





PostPosted: 2005-10-18 14:05:00 Top

java-programmer >> chaning label sizes during runtime On Tue, 18 Oct 2005 02:58:12 GMT, Daniel
<email***@***.com> wrote or quoted :

>Any suggestions for any other layoutmanagers that may handle this
>better?

Others will give you quite different advice, but I find myself giving
up often on other layout managers and reverting to GridBagLayout that
lets me bludgeon the layout into submission rather than finessing it.

see http://mindprod.com/jgloss/gridbaglayout.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.