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 / General / February 2007

Tip: Looking for answers? Try searching our database.

Button text on top of a button icon

Thread view: 
Parachute - 26 Feb 2007 15:10 GMT
Is there a possibility to place the JButton text _on top_ of a JButton
icon instead of next to it (which is the default if the constructor
new JButton(String text, ImageIcon icon) is used)?
I would like to be able to place the text above the image. If there
was a way to create an icon that not only includes a background colour
but also text on it, this would also be nice. But I wasn't able to
produce such an icon either (except separately in an image-editing
programme which I want to avoid).
Thanks for any help!
Andrew Thompson - 26 Feb 2007 15:31 GMT
> Is there a possibility to place the JButton text _on top_ of a JButton
> icon instead of next to it (which is the default if the constructor
> new JButton(String text, ImageIcon icon) is used)?
> I would like to be able to place the text above the image.

Extend JButton and overide paintComponent()
(and probably getMinimumSize()/getPreferredSize()).

Andrew T.
Parachute - 27 Feb 2007 07:23 GMT
Hi,

> Extend JButton and overide paintComponent()
> (and probably getMinimumSize()/getPreferredSize()).

I finally found an easier solution:

start_button = new JButton("Start", new GradientIcon(Color.blue,
Color.gray));
start_button.setHorizontalTextPosition(0);

Setting the horizontal text position to 0 places the text above the
image.

Thanks anyway!


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.