Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

MouseAdapter Bug ??????

Thread view: 
guyzdancin - 09 Oct 2006 00:04 GMT
I have a JPanel with two JButtons.  Each button and the JPanel itself
have the same class type of extended MouseAdapter added.  Code for the
Adapter as follows:

   public class CursorContextListener extends MouseAdapter{
       public void mouseEntered(MouseEvent e){
           Component component = e.getComponent();
           if(component instanceof JButton){
               component.setCursor(new Cursor(Cursor.HAND_CURSOR));
           }
           else{
              component.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
           }
       }
   }

When the JFrame is instantiated, Button1.setVisible(true) and
Button2.setVisible(false) are called.

If the user clicks Button1, following occurrs:

    Button2.setVisible(true)
    Button1.setText("new text")

When user clicks Button2, following occurrs

    Button2.setVisible(false)
    Button1.setText("original text")

Here's the problem:

In the initial state the cursor behaves as designed - ie. it changes to
a hand when moved to any button.  But after Button1 is clicked, the
cursor never changes to hand for Button1 and intermittently changes to
hand for Button2.

Pseudo code for button listeners:

Button1.addActionListener(new ActionListener(){
    public void actionPerformed(){
         if(text == "original text"){
              Button2.setVisible(true)
              Button1.setText("new text")
         }
         else
              ...do something
    }
})

Button2.addActionListener(new ActionListener(){
    public void actionPerformed(){
         Button2.setVisible(false)
         Button1.setText("original text")
    }
})

Can anyone tell me if I'm doing something wrong or is this a java bug.
Using java 1.5

Thanks in advance

Guy
Andrew Thompson - 09 Oct 2006 05:30 GMT
> I have a JPanel with two JButtons.

Please refrain from multi-potsting.

(X-popst to c.l.j.p/g. with f/u to c.l.j.g. only)

Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.