Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass focusTraversalPolicy object to another class  RSS feed

 
Adalberto José Brasaca
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys...

I saw here several examples of focusTraversalPolicy, but in same class. I'm doing a game as College's work (crossword).

I have two classes: Cell and Grid. Cell extends JTextField and I implement a JPopupMenu inside, which will be used to change the focus order (horizontal/vertical). Grid have a bidimensional array of Cells and inside this class I have the focusTraversalPolicy code.

Now, how to pass the focusTraversalPolicy object created on Grid to class Cell where I will call setFocusTraversalPolicy ?

Thanks a lot.

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use targetComponent#requestFocusInWindow(); if the targetComponent is in the currently focused window or targetComponent#grabFocus() if it is in another window.
Recommended reading http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html
 
Adalberto José Brasaca
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:You can use targetComponent#requestFocusInWindow(); if the targetComponent is in the currently focused window or targetComponent#grabFocus() if it is in another window.
Recommended reading http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html


Hmmm... It seems that I need to pass a reference to the container object of JTextField's array instead of own focusTraversalPolicy object. I'll try. Thanks a lot
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!