This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
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?
Joined: Feb 23, 2007
tony xue wrote:oh, will do it. Thank you Pete!
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.
Joined: Apr 10, 2009
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!