Changing cursor when rollover Jbutton

hi All...i need help
i want to change the cursor when i move my mouse over the button into hand cursor, then when the button being pressed, cursor change to Wait cursor
here code of mine..
import java.awt.Color;
import java.awt.Cursor;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
* @author tys
public class cursor_test extends JFrame{
    public cursor_test(){                               
        add_panel panel = new add_panel();              
        add(panel);       
        setBackground(Color.WHITE);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        //GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        setSize(200,200);
        setVisible(true);
        setTitle("Test cursor");
    public static void main(String[] args){
        new cursor_test();
    }//Main  
}//end class frame
class add_panel extends JPanel{
    public add_panel(){
        setLayout(null);
        JButton btn1 = new JButton("button");
        btn1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                  setCursor(new Cursor(Cursor.WAIT_CURSOR));                 
                  //do my program here
                  try{
                      Thread.sleep(1000);                     
                  catch(Exception z){};                                   
                  setCursor(new Cursor(Cursor.DEFAULT_CURSOR));                   
        });//emd ActionListener
        btn1.setSize(90, 30);
        btn1.setLocation(50, 40);
        btn1.setCursor(new Cursor(Cursor.HAND_CURSOR));       
        add(btn1);       
}//end class panelwhat did i do wrong in there...because every time i pressed the button..the cursor still Hand Cursor
Thx
tys
Edited by: KingMao on 22 Sep 08 19:35

Hope this wll helps to you.
class add_panel extends JPanel{
    public add_panel(){
        setLayout(null);
        final JButton btn1 = new JButton("button");
        btn1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                  *btn1.setCursor(new Cursor(Cursor.WAIT_CURSOR));*                 
                  //do my program here
                  try{
                      Thread.sleep(1000);
                      *btn1.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));*                    
                  catch(Exception z){};                                   
                  setCursor(new Cursor(Cursor.DEFAULT_CURSOR));                   
        });//emd ActionListener
        btn1.setSize(90, 30);
        btn1.setLocation(50, 40);
        btn1.setCursor(new Cursor(Cursor.HAND_CURSOR));       
        add(btn1);       
}//end class panel

Similar Messages

  • JTabbedPane - change cursor when mouse over

    Hi
    I want to make the cursor change to the hand cursor when the mouse hovers over each tab.
    Tried
    jtabbedpane..getComponentAt(1).setCursor(new Cursor((Cursor.HAND_CURSOR)));but it changes the cursor for the whole panel not the tab.
    Any idea ?

    Hi,
    I have an idea but no sample code.
    You can register a MouseMotionListener on the JTabbedPane.
    In the mouseMoved event you must check the x,y of the mouse cursor and than you must calculate
    the area of the tabs and when it is inside you change to the hand cursor otherwise to default cursor.

  • How to change cursor when need to open a new dialog?

    Hi,
    I try to change cursor to WAIT when client open a new dialog, which it tell user the program was running to ready display new dialog.
    My code was like the following
    scene.setCursor(Cursor.WAIT);
    someclass.showMyDialog(); // The dialog was a new stage with StageStyle.UTILITY style
    scene.setCursor(Cursor.DEFAULT);
    But the cursor didn't be changed, I didn't know it why? Anybody know it? thank in advance!
    I had search the google, and didn't find the perfect answer, most of they was like to use setCursor(Cursor.WAIT) mode.
    the current ENV in my host was: windows 7 and Java
    java version "1.7.0_13"
    Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
    Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
    Best regards,
    Edited by: user13005878 on May 27, 2013 1:48 AM

    If you have a long running process ("long" means anything the user will notice), you need to run it in a thread other than the JavaFX Application Thread. In other words, you need to change the cursor to the wait cursor on the FX Application Thread, launch a user-defined thread for your long running process (connecting to the database), and once that thread is complete, show the dialog and change the cursor back on the FX Application Thread again. If you try to do everything on the FX Application Thread, you'll likely block that thread and prevent any changes from being visible to the user until the long process is complete (so you'll never see the wait cursor).
    All that said, and as jsmith said, there are some bugs in JavaFX 2.2 with the appearance of the cursor. So on my system (Mac OS X 10.7.5) the "correct" behavior is only observed with JavaFX 8.
    This is an example of doing things wrong. Here I don't see any change to the cursor, even on JavaFX 8:
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Cursor;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    public class WaitCursorDemo extends Application {
      @Override
      public void start(Stage primaryStage) {
        final BorderPane root = new BorderPane();
        final Scene scene = new Scene(root, 600, 400);
        Button button = new Button("Do something time-consuming");
        button.setOnAction(new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            System.out.println("Starting...");
            scene.setCursor(Cursor.WAIT);
            try {
              Thread.sleep(2000);
            } catch (InterruptedException exc) {
              exc.printStackTrace();
            scene.setCursor(Cursor.DEFAULT);
            System.out.println("Done");
        root.setBottom(button);
        primaryStage.setScene(scene);
        primaryStage.show();
      public static void main(String[] args) {
        launch(args);
    }This works on JavaFX 8: after pressing the button I see the wait cursor for two seconds, then it reverts to the default cursor.
    import javafx.application.Application;
    import javafx.concurrent.Task;
    import javafx.concurrent.WorkerStateEvent;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Cursor;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    public class WaitCursorDemo extends Application {
      @Override
      public void start(Stage primaryStage) {
        final BorderPane root = new BorderPane();
        final Scene scene = new Scene(root, 600, 400);
        Button button = new Button("Do something time-consuming");
        button.setOnAction(new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            System.out.println("Starting...");
            scene.setCursor(Cursor.WAIT);
            Task<Void> task = new Task<Void>() {
              @Override
              protected Void call() throws Exception {
                try {
                  Thread.sleep(2000);
                } catch (InterruptedException exc) {
                  exc.printStackTrace();
                return null;
            task.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
              @Override
              public void handle(WorkerStateEvent event) {
                scene.setCursor(Cursor.DEFAULT);
                System.out.println("Done");
                // Display your dialog now you have the data from the database...
            new Thread(task).start();
        root.setBottom(button);
        primaryStage.setScene(scene);
        primaryStage.show();
      public static void main(String[] args) {
        launch(args);
    }

  • Change cursor when using open browswer window behavior

    Okay, I give.  I added an "open browser window" behavior to a line of text, which is working.  How do I get the cursor to change to a finger on rollover?  Thanks!!!!  ttt

    You need to give the text a 'null' link, an example of which Nancy has written for your.
    You may want to take a look at David's Smart Link extension:
    http://foundationphp.com/tools/
    Nadia
    Adobe® Community Expert : Dreamweaver
    Unique CSS Templates | Tutorials | SEO Articles
    http://www.DreamweaverResources.com
    Web Design & Development
    http://www.perrelink.com.au
    http://twitter.com/nadiap

  • Change Cursor When Mousing Over Links In Plug-in Manager

    As it stands, the links are blue - which is fine, but when you mouse over them the cursor doedn't change (nor does the link itself) so they don't look like they're hot. If the mouse doesn't change the link should or something (anything) so the user can tell they're links.
    Thanks,
    Rob

    the above sol will only help you to see the cursor on the local machine
    to make it visible on every machine
    goto column properties >> additional CSS>>in css write cursor:default
    then save changes system wide for these data type
    Also make the same changes in the other datatypes also.......
    cheers
    Ankit

  • How do i change cursor when mouse over a Chart,Graph or Pivot table in 11g

    hello everyone...!!
    I wanted to change the cursor shape from that hand to an arrow .
    As we know whenever the mouse cursor rolls over any button or pivot table ,chart or graphs it changes to a Hand shape, i wanted it to remain in the default arrow shape.
    This is for obiee 11g.
    Please help.

    the above sol will only help you to see the cursor on the local machine
    to make it visible on every machine
    goto column properties >> additional CSS>>in css write cursor:default
    then save changes system wide for these data type
    Also make the same changes in the other datatypes also.......
    cheers
    Ankit

  • Changing cursor when launching table editor

    I have a complex editor for a certain type of data in my table. This editor takes a few seconds to launch so i want the table cursor to change to the wait cursor while it launches. I have created a class extending the DefaultCellEditor and in the getTableCellEditorComponent i have the following...
         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,int row, int column) {
                table.setCursor(Cursor.WAIT_CURSOR);
                //cast the value into a Molecule object
                currentMol = (Molecule)value;
                //launch my editor
                SingleMoleculeView smv= new SingleMoleculeView(currentMol.getProperty("Smiles"),"Edit");
                table.setCursor(Cursor.DEFAULT_CURSOR);
                return smv; //editorComponent;
            }However i get the error
    Error(354,19): method setCursor(int) not found in class javax.swing.JTable
    Anyone have any ideas how a can get this to work ?

    The code compiles fine now i use new Cursor(Cursor.WAIT_CURSOR), however, the cursor doesn't actually change at all, not sure what to do, any ideas ?
    My table is in a JInternalFrame if that has any bearing.
    Thanks

  • I need to change my Cursor when I rollover the Image, Any feature is there in Muse...?

    I need to change my Cursor when I rollover the Image, Any feature is there in Muse, I searched it, But no use, Is there's any plugin is there to do...?

    Click here and request assistance.
    (89404)

  • How do I change cursor to hand pointer when hovering over image?

    Title says it all.
    I'm trying to get the hand cursor when user hovers over an image that's a link.
    Thanks!

    hi.......
    if u want to change the cursor on Image than two property u have to change <......buttonMode="true" useHandCursor="true".....> OR  if u want to change the cursor on label than u have to change <......buttonMode="true" useHandCursor="true" mouseChildren="false".....>
    OR  u can set the mouseOVER event and handler in that u can change the cursor of that ..
    U have two options if u want to keep seprate code then 2nd one is good for u......I hope it will help u ......

  • How do I change the speed of the cursor when using the arrow keys?

    How do I change the speed of the cursor when using the arrow keys?

    Applications folder or Apple icon > System preferences > Keyboard increase key repeat.

  • How to set a busy cursor when the excel report pops-up(in Excel)?

    I'm using LabVIEW 7.1 and Report Generation Toolkit for MS Office to build a VI. at the end of each session when the data in a certain peroid of time was collected, the data will be transmmited to Excel report. the problem is during the poping-up of Excel report, if the cursor clicks inside Excel accidently, all the collected data will disappear and the blanks in Excel will no longer be filled automatically. I have tried to use Set Busy.vi, but it only works in VI panel, not in Excel. Will someone please help me?
    thanks very much

    Hi jingli,
    For changing cursor appearance, you can visit another post on the forum:
    http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RNAME=ViewQuestion&HOID=506500000008000000272E0000&ECategory=LabVIEW.LabVIEW+General
    (search for mouse pointer appearance in this forum if the URL doesn't work)
    Another suggestion would be setting the windows appearance to "minimum" when you open your Excel report (wire it at the New Report VI).
    Dan

  • Link in form of a pictrue - change color when sweeping

    Doing links in form of a word which change color when sweeping over them is simple in iWeb.
    I wonder how I do if I not just want the color of the text but also an image to change.
    Ex. I have a link in form of a bright cloud. When one sweep the mouse over it I want the cloud transform into a darker form of the same cloud.
    Perhaps I need a codescript which connect two pictures of the cloud?
    Johan

    Johan:
    It's called a rollover. There are a number of topics on the subject in this search result page: http://discussions.apple.com/search.jspa?threadID=&q=ROLLOVER&objID=&dateRange=l ast90days&userID=&numResults=30&rankBy=10001. It's done with an HTML Snippet. One of the topics may have an answer for you.
    OT

  • How to change 'cursor'

    Is there a way to change the 'cursor' so that it is always a 'hand' or something else that is easier to see - this is for one of the users that I support. They're looking for the cursor to always be this way, no matter what (ever, regardless). I have not been able to find this feature and other Adobe users I have talked to haven't found anything like it either.

    Hi, showing some messages when moving over a button can be done by standard-functionality useing property "tooltip-text" for the button.
    If you want your own bean start with overwriting the class oracle.forms.ui.VButton, use method with code similar to the following
      protected void processMouseEvent(MouseEvent p0)
        if ((p0.getID()==MouseEvent.MOUSE_ENTERED) && this.isEnabled())
          // Add your code for changing cursor here
          super.processMouseEvent(p0);
        } else if ((p0.getID()==MouseEvent.MOUSE_EXITED) && this.isEnabled())
          // Add your code for changing cursor here
          super.processMouseEvent(p0);
        } else
          super.processMouseEvent(p0);
      }hope this helps

  • Change cursor to hourglass

    i want to change cursor to hourglass when a new servlet is loading. working of my program is that on click of submit,the present servlet unloads and a new servlet is loaded.this new servlet takes time. so i can't write the code in prevoius servlet for cursor and the new servlet which is being loaded changes cursor to hourglass only after fully loading. please help me in this regard

    Write the javascript, flush the output stream, and the hourglass should be shown right away...
    note: You should write some stuff before the javascript -- send some text maybe the top of the output page. IE has some internal buffer you have to fill up before server-side flushing works.
    Again: You should make sure you send the javascript and flush before you start processing.
    Also: You will not be able to do a send redirect if you use this approach. If this is not satisfactory, you could try using one of the "Please Wait" mechanisms described on this site (use the forum or google search for JSP "Please Wait" to find them) to do the job.

  • Change cursor over text fields

    Does anyone know how to change the mouse cursor, to a karat cursor, when the mouse is "hovering" over a JTextField or JTextArea?

    OK heres where I get lost...
    If you run this program then move the mouse over the JTextField the JFrame will change the cursor to a TEXT_CURSOR but the JDialog will not.
    Can anyone make this happen for a JDialog??
    import java.awt.Cursor;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class JDialogMouseTest extends JPanel{
        JTextField textField;
        public JDialogMouseTest(){
            textField = new JTextField();
            textField.addMouseListener(new MouseListener(){
                public void mouseClicked(MouseEvent e) {
                public void mousePressed(MouseEvent e) {
                public void mouseReleased(MouseEvent e) {
                public void mouseEntered(MouseEvent e) {
                    mouseEnteredEvent(e);
                public void mouseExited(MouseEvent e) {
            add(textField);
        private void mouseEnteredEvent(MouseEvent e){
            textField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
        public static void main(String[] args){
            JDialog dialog = new JDialog();
            JDialogMouseTest mouseTest = new JDialogMouseTest();
            dialog.setContentPane(mouseTest);
            dialog.pack();
            dialog.setVisible(true);
            JDialogMouseTest mouseTest1 = new JDialogMouseTest();
            JFrame frame = new JFrame();
            frame.setContentPane(mouseTest1);
            frame.pack();
            frame.setVisible(true);
    }Message was edited by:
    boom_zap

Maybe you are looking for

  • Sound EDL

    I am working on a feature length film that was shot entirely HD. (yes I know thats not really film) I captured all the files using FCP's log and capture feature. The audio was recorded as a mix-down in the camera as well as second system. We cut usin

  • Interactive Report actions don't work for users (i.e. for non-developers)

    I've Interactive Reports that work fine in development. But when I or other users run it in non-development mode, no feature or actions (sorting, filtering, select columns, aggregate, etc.) work. At run time (going directly to the URL ...apex/f?p=APP

  • HDMI AV Digital doesn't run with IOS 6!!!!!

    I have the AV Digital adapter for iPad and iPhone. Now with the new IOS 6 it doesn't run!! Why??? Will you resolve it? Thank's :) :)

  • Find different

    Hello, i am learning java. I want to find out how to find different between two intergers. In C i use mod function but Java I am not sure. ap

  • Need a Telnet Client Implementation in Java

    Hi, I am looking for a Telnet Client Class in Java. Any pointers on this is appreciated. regards, jitu