Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CardLayout problem

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I there,

I have the following set-up in my JFrame...


Then to swap the cards I do 'cl.next(getContentPane());'
This works, and the new Drawer object is displayed.

However, both Drawer objects have their own Listener object, but when drawer2 is on screen, any mouse actions are still captured by the drawer3's listener class (not drawer2's), and applied to the 'card' drawer3 which is behind the 'card' drawer2.

So when drawer3 'card' is selected you can clearly see that the mouse actions have affected it, where it should have been applied to drawer2.

Hope this isn't too confusing, is there any way to solve this?
I guess I could just use 1 listener class for both objects, I'm not sure.

Thanks
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have the Drawer class to test this, but you could try adding
a ComponentListener to the Drawer class itself, or to the component in Drawer
class that has the mis-behaving listener, and in componentShown() have

[component].requestFocusInWindow();
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out,
The Drawer2 object has a Listener class added to it...

// In constructor
TwistRotationListener trl=new TwistRotationListener(this);
addMouseListener(trl);
addMouseMotionListener(trl);

And same for the Drawer3 object, but for some reason in the
TwistRotationListener class, I was storing the Drawer object as static.

Which explains why it was only working for Drawer3 object.

I've made it non-static and it works fine.

Thanks for advice anyway.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!