• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

FocusTraversalPolicy not working

I have a gui with some JTextfiles. Most of the are disabled, but some are editable. At the bottom are 3 buttons which of one is diabled (either number 1 or number 2). Now I was asked to set focus on the third button (Cancel) just to avoid people my accident delete the data in the JTextfiles. I added a FocusTraversalPolicy. I have used it before in other projects. I put the 3 buttons in the list to avoid messing with the fields, but I do not get any effect at all. The same JTextfiled has the initial focus. What can I do? DOes the Layout manager have any effect?
This is the call I do? Where do I need to call it?
getRootPane().setFocusTraversalPolicy(policy);

Open in new window

0
mdoland
Asked:
mdoland
  • 2
  • 2
1 Solution
 
mdolandAuthor Commented:
As it seems now, the problem comes from that the GUI doesn't contain a layout manager. It is initiated with null. What is the best way to at least avoid that one of the fields will be the deafult component?
0
 
ksivananthCommented:
can you post the policy implementation?
0
 
ksivananthCommented:
or you may try with requestFocusInWindow, check this example http://download.oracle.com/javase/tutorial/uiswing/misc/focus.html
0
 
mdolandAuthor Commented:
None of this seems to work. I think it has to do with that no layout manager is used.It looks like this:

<code>
getContentPane().setLayout(null);
</code>

It put focus on the top component what ever I do.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now