my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes Panel to acts like Button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Panel to acts like Button" Watch "Panel to acts like Button" New topic

Panel to acts like Button

Anil Patil

Joined: Oct 20, 2008
Posts: 2
I wanted to create Panel which will acts like a button.
In panel i ll use labels and textbox, and whole panel should have property of button.

Or in Button, it is possible to put labels and text area
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46405
Yes, it is possible to add a text box to a button. Or you can use extends. Or you can have a button occupying the whole of a panel, and set the button to be transparent.

But all those suggestions appear bad design to me; a button is a button, not a text box, and a panel is a panel, not a button.
Anil Patil

Joined: Oct 20, 2008
Posts: 2
Hi Ritchie,

Thanks for suggestion, But my requirements are specific.

Can you elaborate more how can add Labels in button, as I am new to Swings/AWT components
Darryl Burke

Joined: May 03, 2008
Posts: 5115

JComponent extends Container, so all JComponent subclasses including JButton can be used (or abused) as a container.

I am new to Swings/AWT components

Recommended reading: The Java� Tutorials : Creating a GUI with JFC/Swing

luck, db
There are no new questions, but there may be new answers.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Also good reading:

GenRocket - Experts at Building Test Data
I agree. Here's the link:
subject: Panel to acts like Button
It's not a secret anymore!