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 / GUI / December 2004

Tip: Looking for answers? Try searching our database.

jbutton/jlabel disspearing text

Thread view: 
am203 - 13 Dec 2004 13:03 GMT
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 - 13 Dec 2004 13:04 GMT
> 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@comcast.net - 14 Dec 2004 01:11 GMT
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 - 14 Dec 2004 17:32 GMT
> 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)

Signature

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



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.