Solved

JLabel on JButton

Posted on 2004-09-15
14
446 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 250 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now