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 Image in place of  buttons 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 "Image in place of  buttons" Watch "Image in place of  buttons" New topic
Author

Image in place of buttons

Sam Cala
Ranch Hand

Joined: Jan 03, 2001
Posts: 147
Hi,
I wanna use image as buttons in place of simple buttons provided by java.awt package, in addition to this, I also wanna change mouse cursor to 'hand' whenever the mouse has come over that image. But dont know how to go about all this. Can anyone help me out !!!
Regards and thanx in advance,

Best wishes,
Jahanzeb Sayal
Greenhorn

Joined: Mar 02, 2001
Posts: 21
Images(Icons) cant be displayed in Button class provided by java.awt package because it is an OS widget . The most you can try is that u can extend Button class & override its paint method draw image there it will be shown instead of rectangular button but i havent tested it in detail & i got poor results you better use swing JButton.
You can change the curosr on the button by using setCursor(Cursor cursor) of the Component class super class of every component in java.
Check java documentation for details.

[This message has been edited by Jahanzeb Sayal (edited April 21, 2001).]


Sayal
Sam Cala
Ranch Hand

Joined: Jan 03, 2001
Posts: 147
Hi,
Using swing is totally out of consideration as my clients are all web based and even the latest versions of popular browsers doesnt support swing. The clients will need to download the plugin first and then only they can acces my swing enabled site.
Is there some other way out ?
regards and thanks ,
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I have previously posted code to how to make an image button in this thread...
As far as changing the cursor goes... simply add a MouseListener to your button and do a setCursor( Cursor c) on a mouseEntered event, and set it back to the old cursor on the mouseExited event... look at the Cursor class in the API to find out what cursor you need to send to setCurser to get the hand... I think it is Cursor.HAND_CURSOR...
So, you would have something like this in your mouse listener...


HTH,
-Nate
[This message has been edited by Nathan Pruett (edited April 23, 2001).]


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Hi Sam,
java.awt does not support the icon property associated with
a button. However, the same functionality can be done with swing's JButton.

Please note an extra space after the < applet tag and < /applet tag .


[This message has been edited by Ravindra Mohan (edited April 24, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image in place of buttons