File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Button appearance in AWT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Button appearance in AWT" Watch "Button appearance in AWT" New topic

Button appearance in AWT

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Can someone suggest me how to change the appearance of a button ? I want to display a button which will have an appearance of a pressed button after it is clicked for the first time.
sailesh gadia

Joined: Feb 04, 2001
Posts: 5
I guess you can use 2 separate gifs.
1 for normal state and other for pressed state(i.e. when button is pressed)
See the code for Swing :
BTNGo.setIcon(new javax.swing.ImageIcon(getClass().getResource("normal.gif")));
BTNGo.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("pressed.gif")));
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
Yeah, you'd need to use Swing - the appearance of buttons in AWT is set by the OS.
If you need to use AWT, there might be some way of stopping the button recieving events once it's depressed, so it never changes it's appearance.
I agree. Here's the link:
subject: Button appearance in AWT
It's not a secret anymore!