JLabel on JButton

Hi,


I wanna know whether I can put a JLabel on a JButton??  If so, how can I do so???



Xenia
xenia27Asked:
Who is Participating?
 
objectsCommented:
sure you can, try:

button.setLayout(mylayout);
button.add(label);

why do you need to?
0
 
xenia27Author Commented:
"mylayout" would be???  I'm just curious how can I do so...^^
0
 
objectsCommented:
you can already specify text and image to use on button.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
objectsCommented:
> "mylayout" would be???

whatever layout manager you wanted to use
0
 
xenia27Author Commented:
by the way, how can I set the alignment of JButton?

I mean if I want to have a text and JLabel...
0
 
xenia27Author Commented:
will it be ok to put two or more JLabel on the JButton???
0
 
objectsCommented:
Why can't you just use a button, what exactly do you want the button to look like?
0
 
objectsCommented:
> by the way, how can I set the alignment of JButton?

depends on what you want to align

> will it be ok to put two or more JLabel on the JButton???

you can add things to it the same as you would for a panel.
0
 
xenia27Author Commented:
Like if I wanna put my JLabel on the left hand side of my text...
0
 
objectsCommented:
Depends on the layout manager you are using
0
 
xenia27Author Commented:
Should I use the same way I set up an icon and the text in one JButton???
0
 
objectsCommented:
you can use the setText() and setIcon() method of the button to set the text and icon.
0
 
xenia27Author Commented:
OK...Thank you~
0
 
objectsCommented:
no worries :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.