aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JButton with icon as background and button name as pop up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton with icon as background and button name as pop up " Watch "JButton with icon as background and button name as pop up " New topic
Author

JButton with icon as background and button name as pop up

david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
Hi,

I want to create a few buttons vertically on right side of a window, these buttons take images/icons as background, but do not show button name, only when mouse is moved to the button, button name will be shown beside the mouse, like those icons on the tool bar. And when a checkbox is clicked, these button can be disabled. Could I use Jbutton to do this? How?

Thanks.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Yes, a JButton can do this. You can give any Swing JComponent a tool tip, and I suggest you study the tool tip section of the Sun Swing tutorial for more information. Also, to disable /enable a button or any JComponent, simply call its setEnabled(boolean enabled) method.

how to use tooltips
david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
oh, will do it. Thank you Pete!

One more question, seems the button size is affected by the icon size when I use . Since icons have different sizes, but I want all button to have same size, seems it does not work even I use method. Any idea? Should I create new icons that have same size?
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
tony xue wrote:oh, will do it. Thank you Pete!

You're welcome!


One more question, ...
Any idea? Should I create new icons that have same size?


One possible solution: If your JButtons are held in a JPanel that uses GridLayout, they'll all be the same size. For example, if the JButtons are held horizontally, then using a GridLayout(0, 1, 0, vGap) could work well where the parameters mean it will have a variable number of rows, one column, and a vertical spacing between JButtons of vGap size.
david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
Thank you Pete. I am using BoxLayout, since the buttons only occupy upper part the panel, there is blank space below buttons. If I use GridLayout as you told, I guess I need create another smaller panel in which the buttons will occupy the whole panel and get same size, I will think about it. Anyway, thank again for the prompt help!
 
jQuery in Action, 2nd edition
 
subject: JButton with icon as background and button name as pop up