Is there a built in cursor that will show the "arrow plus hourglass" mouse pointer that is used when windows is working in the background, yet still allowing you to click on things?
I know about WAIT_CURSOR, but I don't see anything like this. Do I need to make a custom cursor to get the hourglass-pointer combo?
I don't see a built-in cursor that does this. All the pre-defined cursors reside here:
http://download.oracle.com/javase/7/docs/api/java/awt/Cursor.html
as you may well know.
You will need to create a custom cursor or find someone who has already done this. Here's a website showing you how to build your own custom cursor:
http://blog.codebeach.com/2008/02/using-custom-cursors-in-java.html
Goodluck
Related
I'd like to make a custom help cursor by "badging" the built-in default mouse cursor with a question mark when the user is hovering over an object that can be clicked for context-sensitive help. I'd like this to work nicely across platforms/look-and-feels (to look consistent with the white Windows mouse and the black Mac mouse, for instance.) Is there a way to get the cursor Image from the current Toolkit so that I could generate a combined Image to set as the cursor?
This question points out that the information can't be gotten from the Cursor object. There's also a comment there that suggested fishing around in the JRE, which I've also tried a bit: There and in google images, I didn't find any straightforwardly accessible graphics files to plunder
An alternative would be to add a mouseMoved listener and draw manually a little to the right of the cursor (on the parent, I suppose, to avoid clipping at the borders?) but I was a bit concerned about overhead, and in initial explorations, this was looking very complicated. I'd take other suggestions about finding or making a nice help cursor as well. (The hand is the best built-in, but it doesn't say "help" as clearly as a question-mark.)
In general, no. Most cursors are owned by the platform's host operating system, but a few live in $JAVA_HOME/lib/images/cursors/, for example:
$ ls -1 lib/images/cursors/
cursors.properties
invalid32x32.gif
motif_CopyDrop32x32.gif
motif_CopyNoDrop32x32.gif
motif_LinkDrop32x32.gif
motif_LinkNoDrop32x32.gif
motif_MoveDrop32x32.gif
motif_MoveNoDrop32x32.gif
I'm not sure this is the best solution in your case, because a good built-in mouse cursor should be the best. Anyway you can use mouse listeners and draw on a glasspane according to the mouse position. Here's a glasspane drawing example.
Java uses the default system cursor except for the Drag-and-Drop cursor, where it is using it's own cursors.
So for every cursors but DnD, refer to Extract cursor image in Java . JNA has to be used and can be easily added to any Maven project.
For DnD cursors, the solution from trashgod is good.
They can be loaded this way:
private static Path customSystemCursorPath = null;
public static Image loadDnDCursorImage(String cursorName) throws IOException {
if (customSystemCursorPath == null) {
String jhome = System.getProperty("java.home", "????");
customSystemCursorPath = Paths.get(jhome, "lib", "images", "cursors");
}
// TODO change this to retrieve the cursor filename from cursors.properties
cursorName = "win32_" + cursorName + "32x32.gif";
Path cursorPath = customSystemCursorPath.resolve(cursorName);
Image image = ImageIO.read(cursorPath.toFile());
return image;
}
I trying to find a method in java which could tell me when the mouse cursor has entered the borders of a folder or file component. Can anybody refer me to a good document or help me on this?
Mouse events happen within the context of the Java application (not your desktop). I don't think this is possible.
The best you can do is check if the cursor has left your Java application. As user BackSlash mentioned,
you can use PointerInfo to get the pointer coordinates, but you cannot
know if it has entered something that isn't part of your java
application.
http://docs.oracle.com/javase/7/docs/api/java/awt/PointerInfo.html
An alternative option is:
Add an AWTEventListener for focus events. As long as your app has
focus before the button is clicked you'll receive a focus lost event.
Then query for the pointer position.
The limitation is that, of course, your app loses focus. So depending
on what you are ultimately trying to achieve this might not be useful.
Source: https://stackoverflow.com/a/2420208/2498729
Right now, I'm using Java Swing to create a JEditorPane primarily for its ability to have hyperlinks. I've successfully been able to display links and have them execute behavior upon a click, but I'm running into a few problems with formatting.
How can I set the cursor so that it normally is an arrow, but changes to a text cursor when hovering over text? (In essence, the behavior a cursor has within a web browser). I tried
EditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR))
but that made it a text cursor everywhere, even when not hovering over text. Right now, hovering over a link shows a pointer hand; I'd like to maintain that functionality as well.
What is the best way to show tooltips or mouseover text when hovering over a link? I tried modifying the title attribute of the link but nothing showed up.
I was trying to implement links to skip down to a subsection of the page, much like http://en.wikipedia.org/wiki/Xkcd#History would take you directly to the History subsection of Wikipedia's xkcd page. How can I do this?
An answer to any of these would be great (and multiple would be awesome xP). Thanks a lot for your help!
As you said one can simply give answers to a single point as well, let me try one by one, here is the answer for your last Point 3
Just provide an id to your tag like this
<h1><a id = "top"></a>First Line</h1>
Now somewhere in the bottom of your page write this :
<p>Return to TOP</p>
Clicking this link, you will reach the above area of the PAGE.
Points 1 & 2 may be addressed using the approach mentioned here. In particular, the view/model conversion methods will let you condition setCursor() and getToolTipText(), respectively.
You can get source from here http://java-sl.com/JEditorPaneStructureTool.html
It shows how to obtain text view bounds. First you get caret position for current mouse poiunter using viewToModel() method. Then go down the Views tree achieving leaf view and calcualte it's bounds. See this http://java-sl.com/tip_view_rectangle.html
If your mouse pointer in the view's rectangle then your mouse over text.
You can check whether the text in caret position is link and show your tooltip.
Use this http://java-sl.com/tip_links_in_editable.html to see how to detect whether mouse is over link.
Point 3.rd is answered by #nIcE cOw
I will explain my question clearly.
I need to zoom in/zoom out the world map.
When I click on the particular country in map, control should redirected to new page with respective the country.
I dont have any idea about this in java. Please explain the steps to acheive the above task.
As the question is quite general, here is a general answer: Zooming often means, that you want to display a certain percentage of somethin, and not the whole, where your size of the displayed will not change.
But in your case it seems more like a "find a mouse click in a polygon" thing. So you have to add a selection/click listener to whatever widgets you use (Swt? swing? ....?) where you change what your program renders.
It sounds like you may be trying to reinvent the wheel. Google etc have already solved this problem rather well. It might be better to incorporate an existing solution into your application. Have a look at GoogleEarth inside Java Swing.
Is it possible to get a reference to Swing "no Drag "Cursor ,since it is OS Specific, or maybe override it
I think you might be looking for the DragSource class which has bunch of predefined cursors.
I would look into java.awt.Toolkit::createCustomCursor if you want a cursor that is not predefined in java.awt.Cursor
public Cursor createCustomCursor(Image cursor,
Point hotSpot,
String name);
From the Java 6 Documentation:
Creates a new custom cursor object. If the image to display is invalid, the cursor will be hidden (made completely transparent), and the hotspot will be set to (0, 0).
Note that multi-frame images are invalid and may cause this method to hang.