Results 1 to 5 of 5

Thread: mouseover event

  1. #1
    pds8475 is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default mouseover event

    hi iv got a form with 3 buttons and a textarea what i want to do is when the mouse is over the button a decription of the buttons function is displayed in the textarea.
    any ideas on how i would go about writing the event?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    add a MouseListener to the button?
    Java Code:
    		JButton btn = new JButton("Dummy");
    		btn.addMouseListener(new MouseAdapter() {
    			public void mouseEntered(MouseEvent e) {
    				area.setText("Button description here");
    			}
    			public void mouseExited(MouseEvent e) {
    				area.setText("");
    			}
    		});
    :confused:

  3. #3
    tanjo3 is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    Sounds like you could use .setToolTipText() method like:
    Java Code:
    cmdButton.setToolTipText("This is a button.");

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by tanjo3 View Post
    Sounds like you could use .setToolTipText() method like:
    Java Code:
    cmdButton.setToolTipText("This is a button.");
    tanjo, your reply sounds like the best answer to me. Another possible solution if the OP must use a JTextArea is to add a ChangeListener to the JButton since the button's state changes on rollover.

    i.e.,

    Java Code:
             btn.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                   boolean rollover = btn.getModel().isRollover();
                   if (rollover) {
                      textArea.append(btn.getActionCommand() + "\n");
                   }
                }
             });

    But again, my suggestion is much more of a kludge compared to tanjo's excellent suggestion.
    Last edited by Fubarable; 01-30-2011 at 09:30 PM.

  5. #5
    tanjo3 is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

Similar Threads

  1. key event help
    By Kyle227 in forum New To Java
    Replies: 6
    Last Post: 05-09-2010, 06:01 AM
  2. Mouseover question
    By Psyclone in forum AWT / Swing
    Replies: 2
    Last Post: 02-24-2010, 04:16 AM
  3. checking for an event during an event
    By infinity in forum AWT / Swing
    Replies: 22
    Last Post: 04-09-2009, 01:08 AM
  4. Key event
    By ivvgangadhar in forum Threads and Synchronization
    Replies: 1
    Last Post: 12-11-2008, 09:27 AM
  5. Event
    By nt5515 in forum New To Java
    Replies: 0
    Last Post: 02-15-2008, 04:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •