Results 1 to 2 of 2
  1. #1
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Not all methods show in my MouseListener

    When I say in constructor:

    Java Code:
    		this.setToolTipText("Drag and Drop");
    for : public class MainMenuBar extends JMenuBar I have no problems.

    But I add a MouseListener to my MenuBar, and please see the code:
    Java Code:
    		public void mouseEntered(MouseEvent e) {
    			System.out.println("Mouse entered");
    			e.getComponent().setBackground(Color.red);
    		}
    This works fine as well. When I move my mouse over the menubar, it changes to Red.
    But I cant say:

    Java Code:
    e.getComponent().setToolTipText("Drag and Drop");
    Can you please help me why I do not get the setToolTipText method when I try it like this ?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Not all methods show in my MouseListener

    getComponent() returns a reference of type java.awt.Component. That class neither has nor inherits a method setToolTipText(...)

    If you want to use the method, you will have to cast the reference to a type that has that method, which all Swing components inherit from JComponent. It is then your responsibility to ensure the code does not fail at runtime with a ClassCastException.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 3
    Last Post: 05-27-2010, 10:54 AM
  2. can't get x and y from mouselistener
    By j2me64 in forum Java 2D
    Replies: 3
    Last Post: 04-24-2010, 04:57 PM
  3. MouseListener & GUI
    By Suurisa in forum New To Java
    Replies: 2
    Last Post: 10-27-2009, 12:52 AM
  4. i need help for MouseListener
    By sfaxianovic in forum New To Java
    Replies: 2
    Last Post: 08-21-2008, 03:30 AM
  5. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 06:20 AM

Posting Permissions

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