Solved

FocusTraversalPolicy not working

Posted on 2010-09-15
4
537 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
ID: 33683316
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
ID: 33689013
can you post the policy implementation?
0
 
LVL 26

Accepted Solution

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

Author Comment

by:mdoland
ID: 33689374
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

896 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

13 Experts available now in Live!

Get 1:1 Help Now