Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

JLabel on JButton

Hi,


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



Xenia
0
xenia27
Asked:
xenia27
  • 8
  • 6
1 Solution
 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now