Results 1 to 4 of 4
Thread: Using a cursor
- 11-26-2007, 12:42 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 8
- Rep Power
- 0
- 11-26-2007, 05:36 PM #2
You can set the System crosshair cursor with methods in the Cursor and Component classes
Add a MouseMotionListener for mouseMoved events or a MouseListener for mousePressed events to your component and you can get the coordinates of the mouse position on the component from their MouseEvent e.getPoint.Java Code:Component c = your component c.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); // to change back c.setCursor(Cursor.getDefaultCursor());
- 11-26-2007, 08:30 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 8
- Rep Power
- 0
When you say
What librarys do i need to import....Java Code:Component c = your component
Also is C the variable name you are initialising??
So i could change it to Component crosshairCursor = your component?
Also whats your component mean....
Sorry for being thick, but a good reply hard wired
- 11-26-2007, 10:56 PM #4
It was pseudo code. If I have a gui with a component displayed and I want to set the cursor for the component, ie, when the mouse is over that particular component the cursor will be set according to what I specified for the component, and if the component is:
If you do not like the System cursor you can make an image of what you want and use it with the Toolkit.createCustomCursor method to make what you want.Java Code:JPanel panel = new JPanel(); // The "panel" is the reference to the Component that we use to set the cursor. // Since JPanel extends from Component we can use the (inherited) Component // method [i]setCursor[/i] on the "panel" reference. panel.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
Similar Threads
-
How to Hide cursor
By priya in forum Java SoftwareReplies: 1Last Post: 12-09-2010, 09:39 PM -
GUI cursor change problem
By ludragon in forum Advanced JavaReplies: 2Last Post: 01-09-2008, 10:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks