My own Cursor in Java
Hi,
I'm working on some kinda Drag N Drop program, and I want to to draw the object as cursor while dragging.
I found out how to change the cursor to another default cursor, but of course I need to create a cursor myself.
My question is: how can I use one of my own drawings as Cursor? The API doesn't give me anything about custom cursors.
I'd really be helped out here, thanks in advance!!
Found something with java.awt.Toolkit.createCustomCursor(..,..)
However the problem is that this method wants an Image as argument, while I want to draw the cursur myself.
I need to display the objects name in the cursor. Anybody knows how to do that?
Similar Messages
-
Hello.
I would like to program a Drag-and-Drop like, and I need to use my own cursor during the drag.
I use the createCustomCursor function, but the program never run correctly and exit with a Divide by zero Exception !
Here is my code (in a Canvas) :
Toolkit tlk;
Image img;
Cursor cur;
tlk = getToolkit(); // I've also tried : tlk = Toolkit.getDefaultToolkit();
img = "dndred.gif"; // the file exists, it is displayed on the Canvas
cur = tlk.createCustomCursor( img, new Point( 1, 1 ), "DragAndDrop" ); // Exception when running
setCursor( cur );
Here the printStackStrace :
Exception in thread "main" java.lang.ArithmeticException: / by zero
at sun.awt.motif.X11CustomCursor.createNativeCursor(X11CustomCursor.java:114)
at sun.awt.CustomCursor.<init>(CustomCursor.java:80)
at sun.awt.motif.X11CustomCursor.<init>(X11CustomCursor.java:26)
at sun.awt.motif.MToolkit.createCustomCursor(MToolkit.java:503)
at DragNDrop.<init>(DragNDrop.java:27)
at princ.main(princ.java:6)
Is my code wrong ?
I'm under Linux Debian. dndred.gif is a GIF image, exists, and is 20x20 (I've also tried a 50x50 image).
The function getBestCursorSize( 50, 50 ) returns 32x32.I just seen an error in the code above, I've forget 1 line.
But the problem remain the same.
Toolkit tlk;
Image img;
Cursor cur;
tlk = getToolkit(); // I've also tried : tlk = Toolkit.getDefaultToolkit();
img = tlk.getImage( "dndred.gif" ); // the file exists, it is displayed on the Canvas
cur = tlk.createCustomCursor( img, new Point( 1, 1 ), "DragAndDrop" ); // Exception when running
setCursor( cur );
Please help me. -
How i can make my own connection in java source of a jsp page
How i can make my own connection in java source of a jsp page (How to get connection from JNDI datasource address) ?
imagine that i have a rowset in a web page , now i want to do some operation using
plain JDBC , so i will need a connection object.
I tried to get one of my rowsets connection but it return null ?
what is best way to retrive a connection from JNDI datasource that we define for our project?
for example if i have
myRowSet.setDataSourceName("java:comp/env/jdbc/be");
in web page constructor
now i want a pure connection from the same datasource ? JNDI
Thank youIt is not hard to get your own connection from datasource.
in your case you need to do like the the following code.
i provide sample to show you how to catch the exception and create an statement .
Connection con =null;
try{
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/be");
con = ds.getConnection();
java.sql.Statement st =con.createStatement();
}catch(SQLException sqlex){
sqlex.printStackTrace();
sqlex.getNextException().printStackTrace();
catch(NamingException nex){
nex.printStackTrace();
hth
Masoud kalali -
How to deprecate my own method in java
How to deprecate my own method in java, so that my compiler gives a warning when i use a deprecated method?
Mark it as deprecated as specified in the javadoc guide, (available on this site). You deserve an RTFM but I'm feeling nice today ;->
-
When I try to open a gradebook program called powerschool, I get a message that Java is not deteced, but my computer indicates that it has Java. I can't download any version of Java because I get a message that Apple has its own version of java. My computer indicates that no new software updates are needed.
Start here: http://support.apple.com/downloads/#java
-
Can I provide my own implementation of java.security.acl.Acl ?
Hi,
If I write my own securrity realm, am I able to use my own implementaion of
'java.security.acl.Acl' and 'java.security.acl.AclEntry' or do I have to use
the implementation provided by weblogic ? When Security.checkPermission() is
called, does it solely rely on APIs defined in 'java.security.acl' or does
it really expect to talk to an instance of weblogic 'AclImpl' ?
Thanks, Alexandre.
Alexandre Vauthey
Software Engineer
Application Networks
444 Ramona street
Palo Alto, CA 94301Yes, you can do this.
Alexandre Vauthey wrote:
Hi,
If I write my own securrity realm, am I able to use my own implementaion of
'java.security.acl.Acl' and 'java.security.acl.AclEntry' or do I have to use
the implementation provided by weblogic ? When Security.checkPermission() is
called, does it solely rely on APIs defined in 'java.security.acl' or does
it really expect to talk to an instance of weblogic 'AclImpl' ?
Thanks, Alexandre.
Alexandre Vauthey
Software Engineer
Application Networks
444 Ramona street
Palo Alto, CA 94301 -
How can we position the cursor in Java?
how can we position the cursor in Java? Please help me.
and also provide me the list of threading practical question?I am talking in context of console.Note that the console can be a number of things in Java; command shell, teletype, etc. You can use either JNI or a third-party library such as jcurses for this sort of thing.
~ -
Black Screen with cursor. Java Desktop System.
Hello everyone.
I've installed Solaris 10 05/08 x86 32bit in VMWare Workstation 6.5.
After I logged in in the system (Java Desktop System, Release 3), I've got only a black screen with cursor, nothing more.
X server: Xsun server configuration:
Video Device: VMWare Inc vmware0405
Video Driver: XF86 VMWARE
Resolution/Colors: 800x600 65536 colors @75Hz
Screen size: 17 inch
Monitor type: MultiFrequency 56Hz (up to 1280x1024 interlaced)
But the CDE starts normally.
What's the problem?
Help, please.
P.S. Computer with VMWARE Workstation: Asus P4P800SE, P4HT 3.0Gz, 2.0Gb Ram, Ati AIW X800 AGP 256Mb..
Edited by: xaxaTyH on Oct 9, 2008 7:26 AM
Edited by: xaxaTyH on Oct 9, 2008 7:45 AMHi
Have you installed all the Recommended Patchset . If not try to install the patches .
Regards -
Problem passing REF CURSOR to JAVA STORED PROCEDURE
Hi,
I've written a small Java class with a static method and
imported that into Oracle 8i. The method expects a
java.sql.ResultSet object as parameter. According to the
documentation of Oracle, a REF CURSOR (cursor variable) maps to
java.sql.ResultSet in JDBC.
The definition of the Java Stored Procedure was accepted without
problems:
CREATE OR REPLACE PROCEDURE RESULTSETPASSINGTESTPROC (row
WASTypes.GenericCurType)
as language java
name 'sqlj.ResultSetPassingTest.testResultSetPassing
(java.sql.ResultSet)';
WASTypes is a package containing the definition of the generic
cursor:
CREATE OR REPLACE PACKAGE WASTYPES
is
TYPE GenericCurType IS REF CURSOR;
END WASTypes;
In a function I'm opening the cursor via
'Open cursorVariable for sqlStatement';
Then this cursor variable is passed to the java method and the
error ORA-03113 is shown.
I tried to solve the problem by changing the type of the
parameter to oracle.sql.REF without success.
Does anybody know what wents wrong?
Thanks in advance.
JanHi,
I've written a small Java class with a static method and
imported that into Oracle 8i. The method expects a
java.sql.ResultSet object as parameter. According to the
documentation of Oracle, a REF CURSOR (cursor variable) maps to
java.sql.ResultSet in JDBC.
The definition of the Java Stored Procedure was accepted without
problems:
CREATE OR REPLACE PROCEDURE RESULTSETPASSINGTESTPROC (row
WASTypes.GenericCurType)
as language java
name 'sqlj.ResultSetPassingTest.testResultSetPassing
(java.sql.ResultSet)';
WASTypes is a package containing the definition of the generic
cursor:
CREATE OR REPLACE PACKAGE WASTYPES
is
TYPE GenericCurType IS REF CURSOR;
END WASTypes;
In a function I'm opening the cursor via
'Open cursorVariable for sqlStatement';
Then this cursor variable is passed to the java method and the
error ORA-03113 is shown.
I tried to solve the problem by changing the type of the
parameter to oracle.sql.REF without success.
Does anybody know what wents wrong?
Thanks in advance.
Jan -
is it at all posible in java to create you own event s. and have listeners for them like the one ActionListener has the method actionPerformed(ActionEvent e) can i make my own methods that are triggered by events
and are only called if a new event is generated. like this method it is only called if the use clickes a button.
if there is a way could you please tell or show me how.
many thanksHi,
"Events" are an application of the observer pattern, usually implemented with the event generator idiom in Java. Please see full example in this detailed article.
http://www.javaworld.com/javaworld/jw-09-1998/jw-09-techniques.html -
How to set my own icon for java frame ??
I create a java class it extends JFrame. I want to change default icon on the left_top corner and using my own icon. It is a --.gif file. How to do it. When I try to modify it using setIconImage( Image image), I met problem. I cann't new Image("--.gif"). I don't know how to create a Image object using a string(file name). I try to use ImageIcon , but it is not image obj. Thanks. Gary
According to the documentation setIconImage does the following: Sets the image to be displayed in the minimized icon for this frame. Not all platforms support the concept of minimizing a window.
So,
1) It does not change the icon in the top-left corner
2) It does not work on all platforms. -
I am working on an application in java , where I want to create a
cursor of CrossHair type in which the horizontal and the vertical
hairs/lines should run across the entire screen/panel , and not limited to
32x32 pixel size. With the method Toolkit.createCustomCursor(Image ,
Hotspot , String) one can create cursors with images of one's choice , BUT
ONLY OF 32X32 PIXEL SIZE. How can I overcome this restriction ? Is there
any other way to go about it ?
I shall be obliged if could please help me solve this problem.
Yours sincerely ,
Karunesh TripathiYour idea is worth appreciatoin and holds promise of providing a solution indirectly. I would elaborate my problem further. I want to show this big cursor over a JPanel , occupying a major part of the screen , which is contained in a JFrame alongwith the usual JMenuBar and JToolBar.
In fact , presently , I am already drawing a cross hair across the panel by g2D.drawLine(int , int , int , int) method in paintComponent(Graphics g) of the JPanel. But it does not move as fast as a cursor , especially when the painting load on the panel increases , because the painting of the cross hair at new location can take place only after the method repaint() as well as the event handler returns.
Therefore, the solution may have to be searched in the OS (Windows 98 , in this case) and the basic code of java.awt.Toolkit.createCustomCursor(Image , HotSpot , String).
Your idea may, however , improve the situation significantly , provided the applet is made to float over the JPanel with a transparent background and without borders etc. Can this be done ? I shall be obliged , if you could extend your expertise further. -
Can't change cursor using Java 1.4
Hi all,
I wrote a program that worked while I had my Java Platform set to be 1.5. However, when I set my platform to be 1.4.2 (Java Hotspot) I encounter an error. What would be the best way to make the program work as I would like it to?
The code is:
Toolkit tk = Toolkit.getDefaultToolkit();
Cursor invisCursor = tk.createCustomCursor(tk.createImage(""),new Point(),null);
this.setCursor(invisCursor);that is, I'm trying to hide the mouse cursor in my full-screen application.
When running the program in 1.4, the program works, but the mouse does not disappear and I get the following error:
2006-12-05 14:52:21.935 java[744] *** NSThread: ignoring exception '*** -[NSCFArray objectAtIndex:]: index (2) beyond
bounds (2)' that raised during delayed perform of target 0xa9a8bc20 and selector '_setNativeCursor:'What would be the best way to make my cursor invisible using Java 1.4?
Thanks!Ok, here's my SSCCE that replicates my problem on my computer.
I am using a Mac (didn't get to try it on my PC, but regardless, I need this to work on a Mac), and the problem only occurs when I am using set my libraries to be Java 1.4.2.
The first option in hideMouse() simply fails to hide my mouse.
The second option fails to hide my mouse, and gives me the following error message:
2006-12-06 10:02:27.785 java[394] *** NSThread: ignoring exception '*** -[NSCFArray objectAtIndex:]: index (2) beyond bounds (2)'
that raised during delayed perform of target 0xa9a8bc20 and selector '_setNativeCursor:'It gives me this message only if I move my mouse, and repeats this message for as long as I move my mouse.
My goal is to hide my mouse.
Any help will be more than appreciated.
SSCCE:
import java.awt.*;
import javax.swing.*;
public class MouseExample extends JFrame {
public MouseExample() {
makeFullScreen();
hideMouse();
private void makeFullScreen(){
this.setUndecorated(true);
this.setResizable(false);
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getScreenDevices()[0];
DisplayMode oldMode = device.getDisplayMode();
this.setSize(new Dimension(oldMode.getWidth(), oldMode.getHeight()));
device.setFullScreenWindow(this);
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
System.exit(0);
private void hideMouse(){
// ***** Neither this:
ImageIcon emptyIcon = new ImageIcon(new byte[0]);
Cursor invisibleCursor = getToolkit().createCustomCursor(
emptyIcon.getImage(), new Point(0,0), "Invisible");
this.setCursor(invisibleCursor);
// ***** nor this:
Toolkit tk = Toolkit.getDefaultToolkit();
Cursor invisCursor = tk.createCustomCursor(tk.createImage(""),new Point(),null);
this.setCursor(invisCursor);
// ***** works
public static void main(String[] args) {
MouseExample m = new MouseExample();
} -
Defining your own type in java...?
is there anything similar to C's enum in java for defining your own types?
i.e. id like to make my own boolean type which isnt restricted to just true or false, but rather can be also undefined.
any help will be appreciatedThat has nothing to due with C's enum construct.
No there isn't. I think it will be in the next
version.
Have a look here how to make one:
http://developer.java.sun.com/developer/Books/effective
ava/Chapter5.pdfic, so iz it something like generics? -
REF CURSOR from Java Stored Proc
Does Oracle 8i/9i allow to return REF CURSROR from Java Stored Procedure?
Sorry,
No I don't think this type of Java->SQL mapping was ever fixed. I know it was discussed here on the OTN forums as far back as the 8i driver, but I don't think they have ever implemented this. Perhaps someone who has actually made it work will speak up.
Maybe you are looking for
-
HT201318 How do I cancel my icloud storage plan
I\My acknowledgement says I can cancel within a certain time period, but I can find nothing on my Systme preferences to do so immediately or on the website.
-
Can a mac connect to a TV like a PC can?
My tv has this PC mode, where you can connect your PC. But I don't have a PC, I have a Mac. Can you connect it somehow? By the way, I don't have an Apple TV, if that changes anything.
-
Steps for the IDOC TO FILE with ACKNOWLEDGMENT
Hello experts, Kindly give me the step by step procedure for the following scenario. My scenario is an IDOC( any idoc) for R/3 is coming to XI and send to FTP as XML file with out any modifications, and ftp have to send an response (acknowledgment
-
On my iPod touch 5th generation in Safari iCloud tabs it does not show the tabs I have open on my iPad; and on my iPad it does not show the tabs I have open on my iPod. In iCloud settings safari is turned on, but I'm out of ideas. Could I have some h
-
Unable to open OWA cross site between 2013 and 2010 Exchange Server
Hello, First of all allow me to describe the scenario as this always helps and is often omitted from many questions. SITEA – 1 x 2010 Exchange Server (All roles except UM and Edge), Domain controllers etc available SITEB- 1 x Newly installed 2013 Exc