Google Groups Home
Help | Sign in
label setCursor not working when main frame is maximized
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Chris  
View profile
 More options May 16, 4:33 pm
Newsgroups: comp.lang.java.programmer
From: Chris <cmill...@yahoo.com>
Date: Fri, 16 May 2008 13:33:24 -0700 (PDT)
Local: Fri, May 16 2008 4:33 pm
Subject: label setCursor not working when main frame is maximized
I have a label in a JInternalFrame.  The label has a mouseListener on
it, to listen for clicks but also when the mouse is over the label.
When the mouse is over it, I want to change the cursor to a hand
cursor, and back to normal when exiting the label.  All this works
when my frame & internal frame are their start up sizes, but if I
maximize the main JFrame and then move the mouse over the label, no
hand!  But it's still clickable.  For some reason teh setCursor isn't
working.  But un-maximize the JFrame & things work again.

In the sample code below, I have 2 classes, the main application frame
that extends JFrame, and MyInternalFrame that extends JInternalFrame.
It's in the internal frame that holds the label & mouseListener.

Any help appreciated!!

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;

public class TestLabelLink extends JFrame {
    JDesktopPane desktop;

    public TestLabelLink() {
        super("Test");

        setSize(400,400);

        //Set up the GUI.
        desktop = new JDesktopPane(); //a specialized layered pane

        MyInternalFrame frame = new MyInternalFrame();
        frame.setVisible(true); //necessary as of 1.3
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {}

        setContentPane(desktop);

        //Make dragging a little faster but perhaps uglier.
        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    }

    //Quit the application.
    protected void quit() {
        System.exit(0);
    }

    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        TestLabelLink frame = new TestLabelLink();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Display the window.
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

}

class MyInternalFrame extends JInternalFrame {

    JLabel label = new JLabel("<html><body><a href=\"\">click me</a></
body></html>");

    public MyInternalFrame() {
        super();
        setSize(200,200);

        this.getContentPane().add(label, BorderLayout.NORTH);

        label.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                System.out.println("bang!");
            }

            public void mouseEntered(MouseEvent e) {
                label.setCursor(new Cursor(Cursor.HAND_CURSOR));
            }

            public void mouseExited(MouseEvent e) {
                label.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            }
        });
    }


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Higgins  
View profile
 More options May 16, 6:34 pm
Newsgroups: comp.lang.java.programmer
From: "Jeff Higgins" <oohigg...@yahoo.com>
Date: Fri, 16 May 2008 18:34:49 -0400
Local: Fri, May 16 2008 6:34 pm
Subject: Re: label setCursor not working when main frame is maximized

Just a guess. Do the mouseEnter and Mouse Exit events ever fire when
MyInternalFrame is maximised?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Higgins  
View profile
 More options May 16, 6:43 pm
Newsgroups: comp.lang.java.programmer
From: "Jeff Higgins" <oohigg...@yahoo.com>
Date: Fri, 16 May 2008 18:43:06 -0400
Local: Fri, May 16 2008 6:43 pm
Subject: Re: label setCursor not working when main frame is maximized

Oops! The listener is on the label, sorry.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Higgins  
View profile
 More options May 16, 6:51 pm
Newsgroups: comp.lang.java.programmer
From: "Jeff Higgins" <oohigg...@yahoo.com>
Date: Fri, 16 May 2008 18:51:29 -0400
Local: Fri, May 16 2008 6:51 pm
Subject: Re: label setCursor not working when main frame is maximized

Chris wrote:
>I have a label in a JInternalFrame.  The label has a mouseListener on
> it, to listen for clicks but also when the mouse is over the label.
> When the mouse is over it, I want to change the cursor to a hand
> cursor, and back to normal when exiting the label.  All this works
> when my frame & internal frame are their start up sizes, but if I
> maximize the main JFrame and then move the mouse over the label, no
> hand!  But it's still clickable.  For some reason teh setCursor isn't
> working.  But un-maximize the JFrame & things work again.

Seems to work as you hope here.  WinXP Java 1.6

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Duniho  
View profile
 More options May 16, 7:23 pm
Newsgroups: comp.lang.java.programmer
From: "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
Date: Fri, 16 May 2008 16:23:01 -0700
Local: Fri, May 16 2008 7:23 pm
Subject: Re: label setCursor not working when main frame is maximized
On Fri, 16 May 2008 15:43:06 -0700, Jeff Higgins <oohigg...@yahoo.com>  
wrote:

>> Just a guess. Do the mouseEnter and Mouse Exit events ever fire when
>> MyInternalFrame is maximised?

> Oops! The listener is on the label, sorry.

Well, it is.  But that would still be something for the OP to verify.  
It's possible there's some bug preventing those events from firing when  
the container is maximized, even though he's listening on the label  
control.

Pete


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeff Higgins  
View profile
 More options May 16, 7:56 pm
Newsgroups: comp.lang.java.programmer
From: "Jeff Higgins" <oohigg...@yahoo.com>
Date: Fri, 16 May 2008 19:56:56 -0400
Local: Fri, May 16 2008 7:56 pm
Subject: Re: label setCursor not working when main frame is maximized

Peter Duniho wrote:
> On Fri, 16 May 2008 15:43:06 -0700, Jeff Higgins <oohigg...@yahoo.com>
> wrote:

>>> Just a guess. Do the mouseEnter and Mouse Exit events ever fire when
>>> MyInternalFrame is maximised?

>> Oops! The listener is on the label, sorry.

> Well, it is.  But that would still be something for the OP to verify.
> It's possible there's some bug preventing those events from firing when
> the container is maximized, even though he's listening on the label
> control.

A quick web search reveals Bug Id 6242833, status fixed. Linux, 5.0 , b05.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris  
View profile
 More options May 19, 10:03 am
Newsgroups: comp.lang.java.programmer
From: Chris <cmill...@yahoo.com>
Date: Mon, 19 May 2008 07:03:04 -0700 (PDT)
Local: Mon, May 19 2008 10:03 am
Subject: Re: label setCursor not working when main frame is maximized
On May 16, 6:56 pm, "Jeff Higgins" <oohigg...@yahoo.com> wrote:

I am running on Ubuntu Linux 7.10 using NetBeans 6 IDE.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google