aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Help : Usage of FocusTraversalPolicy in 1.4.2_07 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help : Usage of FocusTraversalPolicy in 1.4.2_07" Watch "Help : Usage of FocusTraversalPolicy in 1.4.2_07" New topic
Author

Help : Usage of FocusTraversalPolicy in 1.4.2_07

David Menfields
Greenhorn

Joined: Jun 28, 2005
Posts: 7
Dear All,

My existing application written in Jdk 1.3.1_15.Now,upgrading to 1.4.2_07.
Compilation in 1.4.2_07 throws so many warnings about the deprecated method setNextFocusableComponent(Component c);

Usage of setNextFocusableComponent
-----------------------------------
Assume 10 components are added in a container like Panel.
We can set the focus in random manner like comp1 ->comp3->comp5->comp4 etc.
So, the coding will be like,

comp1.setNextFocusablecomponent(comp3);
comp3.setNextFocusableComponent(comp5);
comp5.setNextFocusableComponent(comp4); etc ..etc..

Since this particular method is deprecated in 1.4.2_07, i get warnings.
I don't prefer this warnings and need clean compilation.
The alternative solution is implementing FocusTraversalPolicy class.

FocusTraversalPolicy class
---------------------------
It is an abstract class has subclasses ContainerOrderFocusTraversalPolicy and InternalFrameFocusTraversalPolicy .

I have an option to set ContainerOrderFocusTraversalPolicy to my container by the following line .

ContainerOrderFocusTraversalPolicy CTP= new ContainerOrderFocusTraversalPolicy();

panel.setFocusTraversalPolicy(CTP);

The above lines of coding let componets have the sequential order of focus like comp1->comp2->comp3 etc...

But i need to assign the random order of focus to components.

Could anyone please help me in this regard ? what i need to do further ?
Please help me to understand how to use this policy class for my need.
Appreciate your responses.

Sample test program
-----------------------

import java.awt.*;
import javax.swing.*;


public class TestPanel {
public static void main(String args[]) {

JFrame frame = new JFrame();
Container content = frame.getContentPane();
JLabel l1,l2,l3,l4,l5;
JTextField jt1,jt2,jt3;
JComboBox jcb1;
JCheckBox jchb1;

JPanel jp= new JPanel();
l1=new JLabel();
l1.setText("name");

l2=new JLabel();
l2.setText("Age");

l3=new JLabel();
l3.setText("Qualification");

l4=new JLabel();
l4.setText("Male - Yes");

l5=new JLabel();
l5.setText("DOB");


jt1=new JTextField(10);
jt2=new JTextField(20);
jt3=new JTextField(20);

jcb1=new JComboBox();

jchb1=new JCheckBox();

jp.add(l1);
jp.add(jt1);
jp.add(l2);
jp.add(jt2);
jp.add(l3);
jp.add(jcb1);
jp.add(l4);
jp.add(jchb1);
jp.add(l5);
jp.add(jt3);


// deprecated methods commented to avoid warnings in 1.4.2_07
/* jt1.setNextFocusableComponent(jcb1);
jcb1.setNextFocusableComponent(jt3);
jt3.setNextFocusableComponent(jchb1);
jchb1.setNextFocusableComponent(jt2);
jt2.setNextFocusableComponent(jt1);*/

// New policy class
ContainerOrderFocusTraversalPolicy CTP= new ContainerOrderFocusTraversalPolicy();

// setting the policy class in panel
jp.setFocusTraversalPolicy(CTP);

content.add(jp, BorderLayout.CENTER);
frame.pack();
frame.show();
jp.getComponent(1).requestFocusInWindow();
}


}



Thanks and Regards
David Menfields
 
 
subject: Help : Usage of FocusTraversalPolicy in 1.4.2_07
 
Similar Threads
Getting sql error [Microsoft ][odbc microsoft access driver]numeric index out of range
Code!
The INSERT INTO statement contains the following unknown field name: 'OPANo'.
why i am not getting the proper format of the following code
Check Boxes