Solved

FocusTraversalPolicy not working

Posted on 2010-09-15
4
533 Views
Last Modified: 2013-11-23
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
Comment
Question by:mdoland
  • 2
  • 2
4 Comments
 

Author Comment

by:mdoland
Comment Utility
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
 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
can you post the policy implementation?
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
Comment Utility
or you may try with requestFocusInWindow, check this example http://download.oracle.com/javase/tutorial/uiswing/misc/focus.html
0
 

Author Comment

by:mdoland
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now