[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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