File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image in place of buttons

 
Sam Cala
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Jahanzeb Sayal
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Sam Cala
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Ravindra Mohan
Ranch Hand
Posts: 216
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic