This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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