Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JLabel on JButton

Posted on 2004-09-15
14
Medium Priority
?
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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'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.

 
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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses

721 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