Blink custom cursor

Hi to all.
I'm having problems changing the look of the cursor of my app. Sometimes, when the user let the mouse pointer on certain areas of the principal panel, the cursor look must change for a custom look that I have created. The problem is that when I change the aspect of the system cursor, for my custom cursor, it start to blink sometimes, and it stays blinking when I move it on areas where the cursor have to have this custom look. I'm using a code like this.
All this is into a class that extends from JPane.
public void paintComponent(Graphics g) {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image image = toolkit.getImage("CrearTransiciones.gif");
        Point hotSpot = new Point(15, 15);
        Cursor cursor = toolkit.createCustomCursor(image, hotSpot, "CrearTransiciones");
        if (cursorIsOver().equals(ZoneOver.Zone1)) {
            setCursor(cursor);
        } else {
           if (cursorIsOver().equals(ZoneOver.Zone2)) {
               setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
           } else {
              if (cursorIsOver().equals(ZoneOver.Zone3)) {
                  setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
}I have also proved to set the hotSpot into the (0, 0) point, but I'm still having the same problem.
Someone knows what I have to do to avoid the annoying blinking?
Thanks for read.

I think the problem may be the fact that you are changing the cursor in paintComponent() regardless of what the cursor currently is; I would change the code to check if the cursor is already the cursor you want it to be; if so then skip the setCursor().
You are fetching the image every time a paintComponent() call is made. That is not very efficient. I would fetch the image once (in the constructor perhaps?), store the cursor in a member variable and just use it whenever you need it. The rule is that a paint() or paintComponent() call should take as little time as possible, loading and decoding an image from disk is not exactly a fast action.
Also, you are aware that you can do "else if" in stead of nesting the if statements like that?

Similar Messages

  • Custom cursor using image gets resized bigger

    I have created a custom cursor using the following code:
    ClassLoader cl = this.getClass().getClassLoader();     
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image im = tk.getImage( cl.getResource("images/wallcursor.gif"));
    Cursor Custom_Cursor = tk.createCustomCursor(im,new Point(9,9),"Drawing wall");
    draftGrid.setCursor( Custom_Cursor );The cursor is loaded and it works, however - the image I use for the cursor is resized so it gets too big. Any clues on why this happens?
    btw; draftGrid is one of my own classes that extends JComponent.
    - bjorn

    Thanks for your replies guys.
    I tried your code KPSeal, and it works in resizing the cursor image back to its original size. However, a gray square of size 32,32 (which is returned by getBestCursorSize()) is shown round the cursor.
    Here is the updated code (yours hade some minor bugs)
    Image im = tk.getImage( cl.getResource("images/wallcursor.gif"));
    try {
           tracker.addImage(im, 0 );
           tracker.waitForID(0);
    } catch( InterruptedException ie ) {
           ie.printStackTrace();
    int w = im.getWidth(this);
    int h = im.getHeight(this);
    int pw = Toolkit.getDefaultToolkit().getBestCursorSize(w, h).width;
    int ph = Toolkit.getDefaultToolkit().getBestCursorSize(w, h).height;
    System.out.println("w="+w+", h="+h+" - pw="+pw+", ph="+ph);
    Image cim = createImage(pw, ph);
    cim.getGraphics().drawImage(im,0,0, this);                     
    Cursor Custom_Cursor = tk.createCustomCursor(cim,new Point(0,0),"Drawing wall");
    draftGrid.setCursor( Custom_Cursor );The System.out.println statement prints: w=18, h=13 - pw=32, ph=32
    If I try to do the createImage with w and h instead of pw and ph the same gray square (32,32) is created, and in addition the cursor's size is too big which was the probem to begin with ...
    - bjorn

  • Custom cursor using startDrag

    Hello everyone,
    I have a movieclip following my mouse to act as a custom cursor.
    I am using startDrag on the movie clip and mouse.hide()
    What I am trying to resolve is the following:
    I have several hidden simple button objects in the background of my flash movie. ( I am using these to detect when the user has the mouse in certain areas of the flash movie)
    When i go to move over these simple buttons, my custom cursor movieclip stops following the mouse cursor.  Normally my cursor would also then change to the Hand cursor, but i disabled that.
    Can anyone think of any method or hack that would make this work for me?  I would like my custom cursor following the mouse pointer at all times even when hovering over a simple button.
    thanks in advance.

    The cursor changes to hand cursor yet?
    When you say "single button Several hidden objects", the number is?

  • Firefox shows a blinking "edit" cursor in the body of all websites when I click.

    Clicking a button within a webpage puts a blinking text cursor in the body of the site, as if editing a Word document. It's not causing any other problems besides being really annoying and distracting, but it only just started today. I've tried restarting Firefox with add-ons disabled, as well as reinstalling Firefox clean.

    1. try pressing F7
    2. system restore

  • Windows Boots to Black Screen w/Blinking white cursor, and then...

    I installed a new OCZ sata II SSD in my iMac 27' mid-2010.  I bought the cables and pressure wall from an AASP, so it's all Apple in there except for the OCZ drive. The 2TB internal drive (factory) is in there, too.
    Installed SL to the SSD and updated to 10.6.8 and man, does this machine fly now!
    So I used Boot Camp to create a windows partition, 40GB on the SSD, then went through the WIndows 7 install process.  My WIndows disc is a retail copy - totally legit.
    So the installer finishes, and I used the disc that came with the iMac to install the Boot Camp drivers (vs 3.1)
    Then Windows restarts and - fail
    Black screen with blinking white cursor.  Tried the command fixes to the MBR - no joy.
    Here is the weird thing: if I put the Windows installer in the optical drive, then boot to the Startup Disk Manager (holding down option at power up) I can select the installer dvd, and when the prompt comes up "Press any key to boot from CD/DVD" if I just leave it for a moment, the operating system boots from the SSD.
    Weird.  But, thats what I've been doing as a workaround.  That and using Fusion to reach over to the Boot Camp partition and run it as a virtual machine (which works just fine).
    Anybody know how to fix this?
    Thanks!
    Jason

    I FOUND My answer.
    I opened the iMac back up and swapped the SATA data cables so that the cable designated for the factory installed internal HD led to my self-installed SSD - now it works as it should.
    No errors on the internal HD either.
    I beleive that EFI looks for the Windows MBR to be on the 1st drive bay.  If I had modified my system by patching the MBR or EFI somehow I guess I could have got it to work, but as it is the cables reached and all is well.
    As an aside, I came to this deduction when I removed the internal HD from the iMac and tried to boot from the SSD WIN7 partition and still could not.  Then I took the same SSD out and popped it into my MBPro and it worked.  My guess was that somehow the presence of another internal HD of any kind was confusing the boot loader, but I now believe it is the drive bay designation.
    Hope this helps someone else who has added a SSD to their single drive iMac mid-2010

  • How to load and increase size of a custom cursor on a certain monitor (1st or 2nd)?

    In my application I need to load a custom cursor, make it big and display it on the my second monitor in a dual monitor setup to let user click with an additional mouse. I found this thread able to solve the first 2 questions, however the cursor only changes within the VI panel. I had tried but couldn't get a handle to the second monitor, in face, not my primary one as well since I'm not familiar with winapi. I also want to restrict when the user can use the second mouse and only in the second monitor if possible. By the way I am using windows 7 64 bit with Labview 9 32 bit.
    Thanks,

    Ishi,
    More than likely, you are going to have to use Windows OS APIs for this. It sounds like you would like to integrate your program at the operating system level, and will have to make calls to Windows to accomplish this in the proper manner.  You can make calls to Windows in LabVIEW through several methods. Check out this example that sets the position of the cursor via a Call Library Function Node to the Windows SDK.  
    http://zone.ni.com/devzone/cda/epd/p/id/2315
    Cheers,
    Aaron
    National Instruments

  • Custom cursor is too slow in FULL_SCREEN_INTERACTIVE

    My custom cursor is fast in window mode (even maximized) but not in fullscreen where it is really slow.
    Is there a solution to this?

    Dear Rob,
    Thanks for your answer.
    I have put together a simple test case (see attached zip file) and the custom cursor is still "too slow to be usable" in fullscreen mode. Run it and see that the cursor is fast in window mode. Then hit ctrl+enter to go into fullscreen and see how slow the cursor becomes.
    Code:
    package
    import flash.events.MouseEvent;
    import flash.events.KeyboardEvent;
    import flash.ui.Mouse;
    import flash.ui.Keyboard;
    import flash.display.StageDisplayState;
    import flash.display.MovieClip;
    public class Main extends MovieClip
    private var _mousePointer:MousePointer;
    public function Main()
    super();
    Mouse.hide();
    _mousePointer = new MousePointer();
    addChild(_mousePointer);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboardDown);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoved);
    private function goFullscreen(fullscreen:Boolean)
    if(fullscreen)
    stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
    else
    stage.displayState = StageDisplayState.NORMAL;
    private function onMouseMoved(evt:MouseEvent)
    _mousePointer.x = mouseX;
    _mousePointer.y = mouseY;
    evt.updateAfterEvent();
    private function onKeyboardDown(evt:KeyboardEvent)
    if(evt.controlKey && evt.keyCode == Keyboard.ENTER)
    goFullscreen(stage.displayState == StageDisplayState.NORMAL);

  • Custom Cursor and Drag Image in 1.4 DnD

    What is the proper way to provide a custom cursor and drag image in 1.4 DnD? Say we initiate the drag on a component that supports data transfer (such as a JTree).

    Well, this is strange. My app was locking up (100% CPU) when using DND from windows Explorer.
    I noticed that another part of the same appliction was working perfictly. The difference: JFrame .vs. JDialog. I switched the offending JDialog to a JFrame and all works perfictly now!
    java version "1.4.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
    Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
    I would like to switch back at some point, but my g.setXORMode() problem is a much bigger issue for us. (That is, once you enter the XOR mode, you can not go back!)

  • CS6 - Custom Cursor & Button's icon

    I am trying to display a custom cursor when mouse is moving on a button which has icon.
    But the button's icon is always in front of my cursor image.
    How to make my cursor image on top?
    Belows is my code. Please tell me what's wrong.
    Thank you!
    <mx:Application... creationComplete = "init()>
    private var MyCursor:Shape = new Shape();
    private function init():void{
        // draw custom cursor
        MyCursor.graphics.clear();
        MyCursor.graphics.lineStyle(2, 0xFF0000, 1,true);
        MyCursor.graphics.drawCircle(0,0,6);
        MyCursor.graphics.moveTo(-3,-3);
        MyCursor.graphics.lineTo(4,4);
        MyCursor.visible = false;
        // add to the layer
        CursorLayer.addChild(MyCursor);
    private function ShowCustomCursor(e: MouseEvent):void
        Mouse.hide();
        MyCursor.x = e.stageX;
        MyCursor.y = e.stageY;
        MyCursor.visible = true;
    private funtion HideCustomCursor(e:MouseEvent):void
        Mouse.show();
        MyCursor.visible = false;
    <mx:UIComponent id = "CursorLayer" x ="0' y="0" width ="1000" height = "1000" blendMode="layer">
    <mx:Button id="btnTest" x="50" y="5" width="28" height="20" buttonMode="true"
    icon="@Embed(source='assets/btnTest.png')"
    mouseFocusEnabled="true"
    mouseMove="ShowCustomCursor(event)"
    mouseOut="HideCustomCursor(event)"
    tabEnabled="false"
    useHandCursor="true"/>

    that's because your cursor is sporadically moving over your interactive objects interfering with their mouseevents.
    to remedy, disable the mouseEnabled property of your cursor.

  • How do I fix a blinking white cursor upon startup?

    At first this may seem like the same question asked a million times, but I have yet to find an answer for it. So, I was setting up Windows 7 via Bootcamp when my iMac froze. I ended up having to shut down and boot it back up, but now whenever I boot up it does the chime, takes forever to load, and comes up with a blinking white cursor on a black screen. I tried to eject the install disk, do Cmd + R, multiple things with no solution. Please help!

    I am having this problem I get through the whole bootcamp assistant and it restarts and blinking cursor? I tried hard shut down holding alt key to get to boot disc option but I cant get windows to start it just keeps going to black screen with blinking cursor. how did you solve this?

  • Strange vertical bar in address bar blinking near cursor

    After I updated my Firefox to version 33, I noticed that there is strange grey vertical bar keep blinking near cursor in the address bar and sometime it appear near close tab button. How to fix that problem?
    Sorry for my bad english.

    Hello,
    Try disabling graphics hardware acceleration. Since this feature was added to Firefox, it has gradually improved, but there still are a few glitches.
    You might need to restart Firefox in order for this to take effect, so save all work first (e.g., mail you are composing, online documents you're editing, etc.).
    Then perform these steps:
    #Open Firefox ''Options'' window (''Preferences'' on Mac or Linux) as follows:
    #* Click the menu button [[Image:New Fx Menu]] and select ''Options''.
    #In the Firefox Options (or Preferences) window, click the ''Advanced'' tab, then select ''General''.
    #In the settings list, you should find the ''Use hardware acceleration when available'' checkbox. Uncheck this checkbox.
    #Now, restart Firefox and see if the problems persist.
    Additionally, please check for updates for your graphics driver by following the steps mentioned in the following Knowledge base articles:
    * [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]]
    * [[Upgrade your graphics drivers to use hardware acceleration and WebGL]]
    Did this fix your problems? Please report back to us!
    Thank you.

  • Adding a custom cursor to a panel

    HI, I am making a game where i want clicking a radio button to change the cursor image. I have figured out how to create a custom cursor, and even change the current cursor to it. The problem im having is i want to change it while the program is running. I can say somthing like frame.addCursor(cursor) but that sets it permenantly. What i would like is to add it to a panel during run-time. If anyone knows how i would go abou this i would be gratefull.
    Thanks

    Do u mean, upon selecting the radio button, the cursor must be changed to the customized one?
    If it is so,
    u add the snippet in the itemStateChanged() event....of the radiobutton
    i.e.,
    public void itemStateChanged(ItemEvent ie)
    if(ie.getStateChange() == ItemEvent.SELECTED)
    myPanel.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(CursorImg, new Point
    (0,0), "MyCursorImg"));
    CursorImg - the image to display when the cursor is actived
    new Point(0,0) - hotSpot
    MyCursorImg - a localized description of the cursor, for Java Accessibility use
    else
    myPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }

  • Custom Cursors with AS3

    I used the code snippets to create a custom cursor and it works well.  What if I want that cursor to change when it's clicked?  Can I do that easy enough?  Thanks.

    you can use a stage mousedown listener to make it appear your cursor was clicked.

  • Custom Cursors with rollovers.

    So I know how to make a custom Cursor in flash Pro CS5 but if I want that custom cursor to change to something else of my own design when it's over specific objects how would I go about doing that?

    So here's the code for both both buttons and their rollover actions.  Like I said it works fine for one but not the other.  The forward button is fine, but when the back button is clicked it leaves behind a stamp of the rollover cursor.
    /* Mouse Over Event
    Mousing over the symbol instance executes a function in which you can add your own custom code.
    Instructions:
    1. Add your custom code on a new line after the line that says "// Start your custom code" below.
       The code will execute when the symbol instance is moused over.
    backbtn.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler_2);
    function fl_MouseOverHandler_2(event:MouseEvent):void
    parent.addChild(backphoto);
    backphoto.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor_2);
    function fl_CustomMouseCursor_2(event:Event)
              backphoto.x = stage.mouseX;
              backphoto.y = stage.mouseY;
    Mouse.hide();
    /* Mouse Out Event
    Mousing out of the symbol instance executes a function in which you can add your own custom code.
    Instructions:
    1. Add your custom code on a new line after the line that says "// Start your custom code" below.
       The code will execute when the symbol instance is moused out of.
    backbtn.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_2);
    function fl_MouseOutHandler_2(event:MouseEvent):void
    parent.removeChild(backphoto);
    Mouse.show();
    /* Mouse Over Event
    Mousing over the symbol instance executes a function in which you can add your own custom code.
    Instructions:
    1. Add your custom code on a new line after the line that says "// Start your custom code" below.
       The code will execute when the symbol instance is moused over.
    Forwardbtn.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
    function fl_MouseOverHandler(event:MouseEvent):void
    {stage.addChild(nextphoto);
    nextphoto.mouseEnabled = false;
    nextphoto.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor);
    function fl_CustomMouseCursor(event:Event)
              nextphoto.x = stage.mouseX;
              nextphoto.y = stage.mouseY;
    Mouse.hide();
    /* Mouse Out Event
    Mousing out of the symbol instance executes a function in which you can add your own custom code.
    Instructions:
    1. Add your custom code on a new line after the line that says "// Start your custom code" below.
       The code will execute when the symbol instance is moused out of.
    Forwardbtn.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);
    function fl_MouseOutHandler(event:MouseEvent):void
    stage.removeChild(nextphoto);
    Mouse.show();

  • Using custom cursor

    I want to use a cursor from file in my page. How can I do
    this?
    I've found:
    <style>
    <!--
    BODY{
    cursor:url("3dwmove.cur");
    -->
    </style>
    but works only in IE and for all page not only for a link for
    example.

    You can't. Custom cursors are a pain for your visitor, many
    (most? all?)
    of whom will not want to download and install something from
    a site.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Flesky" <[email protected]> wrote in
    message
    news:ehi23v$653$[email protected]..
    >I want to use a cursor from file in my page. How can I do
    this?
    >
    > I've found:
    > <style>
    > <!--
    > BODY{
    > cursor:url("3dwmove.cur");
    > }
    > -->
    > </style>
    >
    > but works only in IE and for all page not only for a
    link for example.
    >

Maybe you are looking for

  • Apps no longer want to update

    Recently (last 2-3 months) my app updates have been accumulating in my Mac App Store. Every time I click update and enter my correct password, the little "loading" pinwheel appears in the top left-hand corner stating that 'something' is happeneing, b

  • What is iTunes unknown error -45054 and how do I get rid of it?

    I cannot download updates to apps because of this error.

  • CLIENT_HOST-Command not working properly

    Hi everyone, i am having trouble on starting a SQL-PLUS-Prompt with the WEBUTIL_HOST-Package. I use the following code to start SQL-PLUS: DECLARE THE_COMMAND Varchar2(100); BEGIN THE_COMMAND := 'PLUS80.EXE scott/scott@database' WEBUTIL_HOST.Blocking(

  • Encountered ORA-01722 Invalid number when query doc from  view

    Hi all, I have the following view. Select item, to_number(wo) a from tablea union all select item, wo from tablebb The problem rise ( ORA-01722) when I try to search for wo from the view after the view has been created. The wo field in tablea was var

  • Not streaming music, video, etc

    My iPad won't stream music, or play videos from YouTube, I player etc. I actually have a work ipad too, which will stream content and have compared settings but cannot see anything different between the two iPads. Ay suggestions?