Solved

JLabel on JButton

Posted on 2004-09-15
14
454 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example using maven 12 108
Glassfish admin console not working 1 88
ArrayList Adding/settign data 3 37
Java pass by reference 3 74
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

734 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