• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JButton with icon as background and button name as pop up

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic