jbutton/jlabel disspearing text  
Author Message
am203





PostPosted: 2004-12-13 21:03:00 Top

java-programmer, jbutton/jlabel disspearing text Hi,

I have created a few JButtons/JLabels but the text on them seems to
disappear depending on the platform the gui is run on (The disappearing text
appears as "..."). How is it possible to set the size of the label/button
according to the length of the text?

Thanks,

Adrien


 
Babu Kalakrishnan





PostPosted: 2004-12-13 21:04:00 Top

java-programmer >> jbutton/jlabel disspearing text am203 wrote:
>
> I have created a few JButtons/JLabels but the text on them seems to
> disappear depending on the platform the gui is run on (The disappearing text
> appears as "..."). How is it possible to set the size of the label/button
> according to the length of the text?
>

If you use appropriate LayoutManagers to layout your GUI, and use pack()
to set the size of your top level frame/window, this should never occur.
The symptom you've described is generally associated with your code
setting fixed sizes to components - either by setting null
LayoutManagers or by setting hard-coded values as the preferredSize of
the component.

BK
 
klynn47





PostPosted: 2004-12-14 9:11:00 Top

java-programmer >> jbutton/jlabel disspearing text Another idea would be to subclass JButton and JLabel and leave the
label blank. Then you could draw text onto the component. Rememeber
that JButton and JLabel are both Components, and you can override the
paint method inherited from Component.

 
 
Andrew Thompson





PostPosted: 2004-12-15 1:32:00 Top

java-programmer >> jbutton/jlabel disspearing text On 13 Dec 2004 17:11:08 -0800, email***@***.com wrote:

> Another idea would be to subclass JButton and JLabel and leave the
> label blank. Then you could draw text onto the component.

Yes. But that is a very silly idea for the same reasons
as LayoutManagers were designed. How are *you* going to handle
text that is too big for the assigned size of the component?

>..Rememeber that JButton and JLabel are both Components,

Specifically, they are Swing components, which is important
to remember when it comes to overring..

>..and you can override the paint ..

..paintComponent(), otherwise they will interfere with tool tips
and menus in the rest of the Swing application.

(snip)

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane