This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Panel to acts like Button" Watch "Panel to acts like Button" New topic
Author

Panel to acts like Button

Anil Patil
Greenhorn

Joined: Oct 20, 2008
Posts: 2
I wanted to create Panel which will acts like a button.
Like
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
Sheriff

Joined: Oct 13, 2005
Posts: 36566
    
  16
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
Greenhorn

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
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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: 15290
    
    6

Also good reading:

http://faq.javaranch.com/java/SwingIsAProperNoun


GenRocket - Experts at Building Test Data
 
 
subject: Panel to acts like Button
 
Similar Threads
Layout ,scrollbar problem
Printing jframe
Is there something like a GroupBox in Swings ?!!
Java Desktop Application Problem
which layout manager to use