• Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom (image) button

 
Panda Mima
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to have my own image in my applet to act as Button. So, I'll have different images -- for Enabled button status, Disabled, with Mouse Over It, when it is Pressed, etc.
But how to create it as a button? The only thing I found is to have regular Button (JButton) _inside_ of which we can have an image. But nothing more...
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JButton has setDiabledIcon(), setDisabledSelectedIcon(), setIcon(), setPressedIcon(), setRolloverIcon(), setRolloverSelectedIcon(), and setSelectedIcon() - all inherited from javax.swing.AbstractButton.
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Panda Mima:
I want to have my own image in my applet to act as Button. So, I'll have different images -- for Enabled button status, Disabled, with Mouse Over It, when it is Pressed, etc.
But how to create it as a button? The only thing I found is to have regular Button (JButton) _inside_ of which we can have an image. But nothing more...


In addition to the methods Mr. Pruett mentioned, there are also setBorderPainted(), setContentAreaFilled(), and setFocusPainted().

Set these to false if you want the button to appear as an unadorned image.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!