Solved

FocusTraversalPolicy not working

Posted on 2010-09-15
4
541 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to edit a midi track 9 164
Notepad++ search not working 6 1,276
error when checking java version 4 4,357
"Primary Reference" Warning in Visual Studio 5 40
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…
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 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.

813 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

8 Experts available now in Live!

Get 1:1 Help Now