Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Trying to get 'frame.getContentPane().getCursor().getType();' to read outside frame

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trying to get 'frame.getContentPane().getCursor().getType();' to read outside frame

    The program below outputs mouse coordinates anywhere on the screen every 500 msec and tries to get the cursor type.

    The problem is cursor type always shows 0.

    Sample output:

    PHP Code:
    C:\Program Files\Java\jdk1.6.0_23\bin>java cursorType
    hello
    (1058837)
    Cursor Type is 0
    (1058837)
    Cursor Type is 0
    (1103818)
    Cursor Type is 0
    (1104816)
    Cursor Type is 0
    (1107867

    PHP Code:
    import java.sql.Timestamp;
    import java.util.Date;
    import java.awt.Robot;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.SystemTray;
    import java.util.Random;
    import java.awt.Cursor;

    class 
    cursorType {

        public static 
    void main(String args[]) throws InterruptedException {

            
    System.out.println("hello");
            
    //1. Create the frame.
            
    JFrame frame = new JFrame("FrameDemo");

            
    //2. Optional: What happens when the frame closes?
            
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            
    //3. Create components and put them in the frame.
            //...create Label...
            
    Label lbl = new Label("Welcome!"Label.CENTER);

            
    frame.getContentPane().add(lblBorderLayout.CENTER);

            
    //4. Size the frame.
            
    frame.setSize(1919999);
            
            
    //frame.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            //5. Show it.
            
    frame.setVisible(true);
            
    int cursorType;
            while (
    true) {
                
    Thread.sleep(500);
                
    System.out.println("(" MouseInfo.getPointerInfo().getLocation().", " MouseInfo.getPointerInfo().getLocation().")");
                
    cursorType frame.getContentPane().getCursor().getType();

                
    System.out.println("Cursor Type is " cursorType);
            }


        }

    *used php tags cause I like its color coding

    I understand that .getCursor().getType(); has to work under the confines of a frame but is there a way to workaround this?

    Bottom line is I want to capture the current cursor type anywhere on my screen.

    Any ideas?
    Last edited by ssbattousai; January 18th, 2012 at 10:49 PM. Reason: The problem is cursor type always shows 0.


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Trying to get 'frame.getContentPane().getCursor().getType();' to read outside fra

    .getCursor().getType()

    doesn't tell what the current cursor is, even if the cursor is over the frame. That method only returns what the mouse would be if it was over that JFrame, JComponent, etc.

    So the best thing I can suggest is finding which Component the mouse is over (or if it's over the JFrame at all), and then return the cursor for whatever component the mouse is hovering over.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Similar Threads

  1. how to set my frame in the middle of the screen
    By chronoz13 in forum AWT / Java Swing
    Replies: 3
    Last Post: February 10th, 2012, 08:13 AM
  2. Filling the frame
    By Metadeth in forum AWT / Java Swing
    Replies: 2
    Last Post: July 11th, 2011, 03:28 PM
  3. [SOLVED] frame closing programmatically
    By nasi in forum AWT / Java Swing
    Replies: 9
    Last Post: May 10th, 2010, 03:43 AM
  4. [SOLVED] frame are exiting at the same time
    By chronoz13 in forum AWT / Java Swing
    Replies: 8
    Last Post: January 25th, 2010, 08:13 PM
  5. how to modify a JList Frame?
    By JM_4ever in forum AWT / Java Swing
    Replies: 0
    Last Post: October 14th, 2009, 11:58 PM

Tags for this Thread