Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JLabel on JButton

Posted on 2004-09-15
14
Medium Priority
?
459 Views
Last Modified: 2012-06-21
Hi,


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



Xenia
0
Comment
Question by:xenia27
  • 8
  • 6
14 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 12071472
sure you can, try:

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

why do you need to?
0
 

Author Comment

by:xenia27
ID: 12071474
"mylayout" would be???  I'm just curious how can I do so...^^
0
 
LVL 92

Expert Comment

by:objects
ID: 12071475
you can already specify text and image to use on button.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 92

Expert Comment

by:objects
ID: 12071476
> "mylayout" would be???

whatever layout manager you wanted to use
0
 

Author Comment

by:xenia27
ID: 12071478
by the way, how can I set the alignment of JButton?

I mean if I want to have a text and JLabel...
0
 

Author Comment

by:xenia27
ID: 12071489
will it be ok to put two or more JLabel on the JButton???
0
 
LVL 92

Expert Comment

by:objects
ID: 12071507
Why can't you just use a button, what exactly do you want the button to look like?
0
 
LVL 92

Expert Comment

by:objects
ID: 12071564
> 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
 

Author Comment

by:xenia27
ID: 12071584
Like if I wanna put my JLabel on the left hand side of my text...
0
 
LVL 92

Expert Comment

by:objects
ID: 12071603
Depends on the layout manager you are using
0
 

Author Comment

by:xenia27
ID: 12071651
Should I use the same way I set up an icon and the text in one JButton???
0
 
LVL 92

Expert Comment

by:objects
ID: 12071674
you can use the setText() and setIcon() method of the button to set the text and icon.
0
 

Author Comment

by:xenia27
ID: 12071741
OK...Thank you~
0
 
LVL 92

Expert Comment

by:objects
ID: 12071769
no worries :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question