Button text on top of a button icon

P

Parachute

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!
 
A

Andrew Thompson

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.
 
P

Parachute

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top