Solved

JLabel on JButton

Posted on 2004-09-15
14
450 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 51
Oracle SQL syntax check  without executing 6 56
Tomcat: Unable to run tomcat service. 2 20
Java: anonymous class 4 22
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

810 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