Well, it says that it's replaced by FocusTraversalPolicy. Have you read
the docs for that? If so, have you tried it? It seems *reasonably*
straightforward to me.
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
thanks
"Jon Skeet" <sk...@pobox.com> wrote in message
news:MPG.16d5d3db2...@dnews.peramon.com...
SwingUtilities.invokeLater(new Runnable() {
public void run() {
myJTextField.requestFocus();
myJTextField.requestDefaultFocus();
myJTextField.grabFocus(); // I know... a no-no!
}
});
Sometimes, only the first line (requestFocus()) is required. Sometimes,
the first two lines. Infrequently, all three lines. This isn't limited
to text fields, but also things like tables, etc.
I've even gone so far as to make this into a static utility function:
public class MySwingUtilities
{
. . .
public static void forceInitialFocus(JComponent comp) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
comp.requestFocus();
comp.requestDefaultFocus();
comp.grabFocus();
}
});
}
. . .
}
--
lar3ry gensch lar...@emuck.com
"As God is my witness, I thought turkeys could fly" - Arthur Carlson
nobody can give an explicit example of how to replace this deprecated
method - only references to the docs of the new focus system, that itself
doesn't tell how to replace setNextFocusableComponent() ... :-(
Personally, I think the answers were very helpful. If you look at the
API doc for setNextFocusableComponent(), it references
FocusTraversalPolicy. FocusTraversalPolicy has a simple API. You pass
it in a component, it tells you what the next one is.
Then you plug it in using...
setFocusTraversalPolicy() on your Container.
--
Shannon Hickey
shan...@swingteam.com
Swing Team http://TheSwingConnection.com http://TheJavaTutorial.com
Java Software, a division of Sun Microsystems, Inc.
i look at the API and try the following:
lastField.setFocusTraversalPoliy(policy);
okay, this is one replacement method. but how to i create the object
"policy"?
i look at the API of FocusTraversalPolicy:
hm, i can create a new FocusTraversalPolicy() but that doesn't help because
this class has no set() method to set the next focusable component.
okay, i see the "Direct Known Subclass" of FocusTraversalPolicy and find
ContainerOrderFocusTraversalPolicy. hm, i could make a new
ContainerOrderFocusTraversalPolicy() but then again: there is no set method
in ContainerOrderFocusTraversalPolicy to set the next focusable component.
end of API help ... so where is the "helpful" information??
you write "You pass it in a component, it tells you what the next one is."
... but HOW???
martin
"Shannon Hickey - Swing Team" <shan...@swingteam.com> schrieb im
Newsbeitrag news:bd02e3f4.02022...@posting.google.com...
The answers point you to the documentation. That's helpful. I think
the problem is that the documentation isn't helping you very much and
I think that's because you're missing the point. You have to
_subclass_ FocusTraversalPolicy and implement the methods to do your
logic.
>
> i look at the API and try the following:
>
> lastField.setFocusTraversalPoliy(policy);
>
> okay, this is one replacement method. but how to i create the object
> "policy"?
>
> i look at the API of FocusTraversalPolicy:
>
> hm, i can create a new FocusTraversalPolicy() but that doesn't help because
> this class has no set() method to set the next focusable component.
>
> okay, i see the "Direct Known Subclass" of FocusTraversalPolicy and find
> ContainerOrderFocusTraversalPolicy. hm, i could make a new
> ContainerOrderFocusTraversalPolicy() but then again: there is no set method
> in ContainerOrderFocusTraversalPolicy to set the next focusable component.
>
> end of API help ... so where is the "helpful" information??
>
> you write "You pass it in a component, it tells you what the next one is."
>
> ... but HOW???
subclass FocusTraversalPolicy. Override the method
getNextFocusableComponent(). In that method, return whatever component
you want.
oh great! i have to write a subclass! for each call of
setNextFocusableComponent ...? that's a big regression - that's crazy! this
would mean instead of calling one method for the last component of each
mask, i have to write a (sub)class for each mask ... just to set the next
focusable component ... that's not true, isn't it!
There are many ways:
1.if the container is a focus cycle root, that's ok, applies your custom
subclass of layoutFocusTraversalPolicy
2.use focus listener and keyboardfocus manager, that's ok, implements
focus listeners on components, and then on focus lost, invoke the keyboard
focus manager to focus your custom target, (or request focus)
but doesn't really match my need, i want to define a focus cycle locally.
Or maybe should navigate from a cycle root to another ???
Example 1 : FocusDemo3.java
inner custom traversal policy applied to the frame(focus cycle
root), and then automatically to all its containers
focus listeners and keyboard focus manager example
Example 2 : OFocusDemo.java , works with OFocusTraversalPolicy.java
extern general traversal policy, and inner custom, inner doesn't
works if the panel (panel_E) isn't a focus cycle root
I would like the same but not jailed in the focus cycle root of the panel_E
!!
I am working on bad ways ??
**************************** START Source FocusDemo3.java
********************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
public class FocusDemo3 extends JFrame {
/**
* Récupération statique du focus manager courant
* ??? Default ???
*/
KeyboardFocusManager focusMgr =
DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager();
public FocusDemo3() {
super("Focus Demo");
this.setName("Frame Demo");
JPanel panelNiveauA = new JPanel();
JPanel panelNiveauB = new JPanel();
JPanel panelNiveauC = new JPanel();
JPanel panelNiveauD = new JPanel();
panelNiveauA.setLayout(new BorderLayout());
panelNiveauB.setLayout(new BorderLayout());
panelNiveauC.setLayout(new BorderLayout());
panelNiveauD.setLayout(new BorderLayout());
panelNiveauA.setBackground(Color.white);
panelNiveauB.setBackground(Color.red);
panelNiveauC.setBackground(Color.blue);
panelNiveauD.setBackground(Color.yellow);
//panelNiveauA.setFocusCycleRoot(true);
//panelNiveauB.setFocusCycleRoot(true);
//panelNiveauC.setFocusCycleRoot(true);
//panelNiveauD.setFocusCycleRoot(true);
panelNiveauA.setBorder(new TitledBorder("Focus Cycle A"));
panelNiveauB.setBorder(new TitledBorder("Focus Cycle B"));
panelNiveauC.setBorder(new TitledBorder("Focus Cycle C"));
panelNiveauD.setBorder(new TitledBorder("Focus Cycle D"));
panelNiveauA.add(getComponentPanelA(), BorderLayout.NORTH);
panelNiveauB.add(getComponentPanelB(), BorderLayout.NORTH);
panelNiveauC.add(getComponentPanelC(), BorderLayout.NORTH);
panelNiveauD.add(getComponentPanelD(), BorderLayout.NORTH);
panelNiveauA.add(getComponentPanelE(), BorderLayout.SOUTH);
this.setContentPane(panelNiveauA);
panelNiveauA.add(panelNiveauB, BorderLayout.CENTER);
panelNiveauB.add(panelNiveauC, BorderLayout.CENTER);
panelNiveauC.add(panelNiveauD, BorderLayout.CENTER);
// ne s'applique que aux focus cycle roots !!
this.setFocusTraversalPolicy(new MyFocusTraversalPolicy());
}
public static void main(String[] args) {
FocusDemo3 frame = new FocusDemo3();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 1.3
frame.pack();
frame.setVisible(true);
//frame.setBounds(0,0,600,450);
}
JPanel panel_A, panel_B, panel_C, panel_D, panel_E;
JButton bt1_A, bt2_A, bt1_B, bt2_B, bt1_C, bt2_C, bt1_D, bt2_D, bt1_E,
bt2_E;
JComboBox combo_A, combo_B, combo_C, combo_D, combo_E;
JTextField tf_A, tf_B, tf_C, tf_D, tf_E;
java.text.DateFormatSymbols dfs = new
java.text.DateFormatSymbols(Locale.getDefault());
String []months = dfs.getMonths();
protected JPanel getComponentPanelA() {
if (panel_A == null) {
panel_A = new JPanel();
bt1_A = new JButton("Button 1_A");
bt2_A = new JButton("Button 2_A");
combo_A = new JComboBox(months);
tf_A = new JTextField("tf_A");
bt1_A.setFocusable(false);
bt2_A.setFocusable(false);
tf_A.setColumns(10);
bt1_A.setName("bt1_A");
bt2_A.setName("bt2_A");
combo_A.setName("combo_A");
tf_A.setName("tf_A");
bt1_A.addFocusListener( new MyFocusAdapter());
bt2_A.addFocusListener( new MyFocusAdapter());
combo_A.addFocusListener( new MyFocusAdapter());
tf_A.addFocusListener( new MyFocusAdapter());
panel_A.setOpaque(false);
panel_A.add(bt1_A);
panel_A.add(bt2_A);
panel_A.add(combo_A);
panel_A.add(tf_A);
}
return panel_A;
}
protected JPanel getComponentPanelB() {
if (panel_B == null) {
panel_B = new JPanel();
bt1_B = new JButton("Button 1_B");
bt2_B = new JButton("Button 2_B");
combo_B = new JComboBox(months);
tf_B = new JTextField("tf_B");
bt1_B.setFocusable(false);
bt2_B.setFocusable(false);
tf_B.setColumns(10);
bt1_B.setName("bt1_B");
bt2_B.setName("bt2_B");
combo_B.setName("combo_B");
tf_B.setName("tf_B");
bt1_B.addFocusListener( new MyFocusAdapter());
bt2_B.addFocusListener( new MyFocusAdapter());
combo_B.addFocusListener( new MyFocusAdapter());
tf_B.addFocusListener( new MyFocusAdapter());
panel_B.setOpaque(false);
panel_B.add(bt1_B);
panel_B.add(bt2_B);
panel_B.add(combo_B);
panel_B.add(tf_B);
}
return panel_B;
}
protected JPanel getComponentPanelC() {
if (panel_C == null) {
panel_C = new JPanel();
bt1_C = new JButton("Button 1_C");
bt2_C = new JButton("Button 2_C");
combo_C = new JComboBox(months);
tf_C = new JTextField("tf_C");
bt1_C.setFocusable(false);
bt2_C.setFocusable(false);
tf_C.setColumns(10);
bt1_C.setName("bt1_C");
bt2_C.setName("bt2_C");
combo_C.setName("combo_C");
tf_C.setName("tf_C");
bt1_C.addFocusListener( new MyFocusAdapter());
bt2_C.addFocusListener( new MyFocusAdapter());
combo_C.addFocusListener( new MyFocusAdapter());
tf_C.addFocusListener( new MyFocusAdapter());
panel_C.setOpaque(false);
panel_C.add(bt1_C);
panel_C.add(bt2_C);
panel_C.add(combo_C);
panel_C.add(tf_C);
}
return panel_C;
}
protected JPanel getComponentPanelD() {
if (panel_D == null) {
panel_D = new JPanel();
bt1_D = new JButton("Button 1_D");
bt2_D = new JButton("Button 2_D");
combo_D = new JComboBox(months);
tf_D = new JTextField("tf_D");
bt1_D.setFocusable(false);
bt2_D.setFocusable(false);
tf_D.setColumns(10);
bt1_D.setName("bt1_D");
bt2_D.setName("bt2_D");
combo_D.setName("combo_D");
tf_D.setName("tf_D");
bt1_D.addFocusListener( new MyFocusAdapter());
bt2_D.addFocusListener( new MyFocusAdapter());
combo_D.addFocusListener( new MyFocusAdapter());
tf_D.addFocusListener( new MyFocusAdapter());
panel_D.setOpaque(false);
panel_D.add(bt1_D);
panel_D.add(bt2_D);
panel_D.add(combo_D);
panel_D.add(tf_D);
}
return panel_D;
}
protected JPanel getComponentPanelE() {
if (panel_E == null) {
panel_E = new JPanel();
bt1_E = new JButton("Button 1_E");
bt2_E = new JButton("Button 2_E");
combo_E = new JComboBox(months);
tf_E = new JTextField("tf_E");
tf_E.setColumns(10);
bt1_E.setName("bt1_E");
bt2_E.setName("bt2_E");
combo_E.setName("combo_E");
tf_E.setName("tf_E");
bt1_E.addFocusListener( new MyFocusAdapter());
bt2_E.addFocusListener( new MyFocusAdapter());
combo_E.addFocusListener( new MyFocusAdapter());
tf_E.addFocusListener( new MyFocusAdapter());
panel_E.setOpaque(false);
panel_E.add(bt1_E);
panel_E.add(bt2_E);
panel_E.add(combo_E);
panel_E.add(tf_E);
}
return panel_E;
}
class MyFocusAdapter extends FocusAdapter {
MyFocusAdapter() {
super();
}
public void focusGained(FocusEvent e) {
System.out.println("Focus GAINED by :
"+((Component)e.getSource()).getName());
}
public void focusLost(FocusEvent e) {
System.out.println("Focus LOST by :
"+((Component)e.getSource()).getName());
if (e.getSource() == tf_D) {
Container container = tf_D.getFocusCycleRootAncestor();
FocusTraversalPolicy policy =
container.getFocusTraversalPolicy();
Component c = policy.getComponentBefore(container,tf_E);
focusMgr.focusNextComponent(c);
}
else if (e.getSource() == tf_C) {
if (! tf_B.requestFocusInWindow()) {
System.out.println("PBPBPBPBPB");
}
}
}
}
class MyFocusTraversalPolicy extends LayoutFocusTraversalPolicy {
MyFocusTraversalPolicy() {
super();
}
public Component getComponentAfter(Container focusCycleRoot,
Component aComponent) {
System.out.print(" - LayoutFocusTraversalPolicy : AFTER :
"+aComponent.getName());
Component c;
if (aComponent == tf_B) {
c = tf_D;
}
else {
c = super.getComponentAfter(focusCycleRoot, aComponent);
}
System.out.println(" ==> "+c.getName());
return c;
}
public Component getComponentBefore(Container focusCycleRoot,
Component aComponent){
System.out.print(" - LayoutFocusTraversalPolicy : BEFORE :
"+aComponent.getName());
Component c = super.getComponentBefore(focusCycleRoot,
aComponent);
System.out.println(" ==> "+c.getName());
return c;
}
public Component getFirstComponent(Container focusCycleRoot) {
System.out.print(" - LayoutFocusTraversalPolicy : FIRST :
"+focusCycleRoot.getName());
Component c = super.getFirstComponent(focusCycleRoot);
System.out.println(" ==> "+c.getName());
return c;
}
public Component getLastComponent(Container focusCycleRoot) {
System.out.print(" - LayoutFocusTraversalPolicy : LAST :
"+focusCycleRoot.getName());
Component c = super.getLastComponent(focusCycleRoot);
System.out.println(" ==> "+c.getName());
return c;
}
protected boolean accept(Component aComponent) {
//System.out.println(" - LayoutFocusTraversalPolicy : ACCEPT :
"+aComponent);
return super.accept(aComponent);
}
}
}
**************************** END Source FocusDemo3.java
**********************
*************************** START Source OFocusDemo.java
********************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
public class OFocusDemo extends JFrame {
public OFocusDemo() {
super("OFocus Demo");
this.setName("OFrame Demo");
JPanel panelNiveauA = new JPanel();
JPanel panelNiveauB = new JPanel();
JPanel panelNiveauC = new JPanel();
JPanel panelNiveauD = new JPanel();
panelNiveauA.setLayout(new BorderLayout());
panelNiveauB.setLayout(new BorderLayout());
panelNiveauC.setLayout(new BorderLayout());
panelNiveauD.setLayout(new BorderLayout());
panelNiveauA.setBackground(Color.white);
panelNiveauB.setBackground(Color.red);
panelNiveauC.setBackground(Color.blue);
panelNiveauD.setBackground(Color.yellow);
//panelNiveauA.setFocusCycleRoot(true);
//panelNiveauB.setFocusCycleRoot(true);
//panelNiveauC.setFocusCycleRoot(true);
//panelNiveauD.setFocusCycleRoot(true);
panelNiveauA.setBorder(new TitledBorder("Focus Cycle A"));
panelNiveauB.setBorder(new TitledBorder("Focus Cycle B"));
panelNiveauC.setBorder(new TitledBorder("Focus Cycle C"));
panelNiveauD.setBorder(new TitledBorder("Focus Cycle D"));
panelNiveauA.add(getComponentPanelA(), BorderLayout.NORTH);
panelNiveauB.add(getComponentPanelB(), BorderLayout.NORTH);
panelNiveauC.add(getComponentPanelC(), BorderLayout.NORTH);
panelNiveauD.add(getComponentPanelD(), BorderLayout.NORTH);
panelNiveauA.add(getComponentPanelE(), BorderLayout.SOUTH);
this.setContentPane(panelNiveauA);
panelNiveauA.add(panelNiveauB, BorderLayout.CENTER);
panelNiveauB.add(panelNiveauC, BorderLayout.CENTER);
panelNiveauC.add(panelNiveauD, BorderLayout.CENTER);
this.setFocusTraversalPolicy(new OFocusTraversalPolicy());
}
public static void main(String[] args) {
OFocusDemo frame = new OFocusDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 1.3
frame.pack();
frame.setVisible(true);
}
JPanel panel_A, panel_B, panel_C, panel_D, panel_E;
JButton bt1_A, bt2_A, bt1_B, bt2_B, bt1_C, bt2_C, bt1_D, bt2_D, bt1_E,
bt2_E;
JComboBox combo_A, combo_B, combo_C, combo_D, combo_E;
static JTextField tf_A, tf_B, tf_C, tf_D, tf_E;
java.text.DateFormatSymbols dfs = new
java.text.DateFormatSymbols(Locale.getDefault());
String []months = dfs.getMonths();
protected JPanel getComponentPanelA() {
if (panel_A == null) {
panel_A = new JPanel();
bt1_A = new JButton("Button 1_A");
bt2_A = new JButton("Button 2_A");
combo_A = new JComboBox(months);
tf_A = new JTextField("tf_A");
bt1_A.setFocusable(false);
bt2_A.setFocusable(false);
tf_A.setColumns(10);
bt1_A.setName("bt1_A");
bt2_A.setName("bt2_A");
combo_A.setName("combo_A");
tf_A.setName("tf_A");
panel_A.setOpaque(false);
panel_A.add(bt1_A);
panel_A.add(bt2_A);
panel_A.add(combo_A);
panel_A.add(tf_A);
}
return panel_A;
}
protected JPanel getComponentPanelB() {
if (panel_B == null) {
panel_B = new JPanel();
bt1_B = new JButton("Button 1_B");
bt2_B = new JButton("Button 2_B");
combo_B = new JComboBox(months);
tf_B = new JTextField("tf_B");
bt1_B.setFocusable(false);
bt2_B.setFocusable(false);
tf_B.setColumns(10);
bt1_B.setName("bt1_B");
bt2_B.setName("bt2_B");
combo_B.setName("combo_B");
tf_B.setName("tf_B");
panel_B.setOpaque(false);
panel_B.add(bt1_B);
panel_B.add(bt2_B);
panel_B.add(combo_B);
panel_B.add(tf_B);
}
return panel_B;
}
protected JPanel getComponentPanelC() {
if (panel_C == null) {
panel_C = new JPanel();
bt1_C = new JButton("Button 1_C");
bt2_C = new JButton("Button 2_C");
combo_C = new JComboBox(months);
tf_C = new JTextField("tf_C");
bt1_C.setFocusable(false);
bt2_C.setFocusable(false);
tf_C.setColumns(10);
bt1_C.setName("bt1_C");
bt2_C.setName("bt2_C");
combo_C.setName("combo_C");
tf_C.setName("tf_C");
panel_C.setOpaque(false);
panel_C.add(bt1_C);
panel_C.add(bt2_C);
panel_C.add(combo_C);
panel_C.add(tf_C);
}
return panel_C;
}
protected JPanel getComponentPanelD() {
if (panel_D == null) {
panel_D = new JPanel();
bt1_D = new JButton("Button 1_D");
bt2_D = new JButton("Button 2_D");
combo_D = new JComboBox(months);
tf_D = new JTextField("tf_D");
bt1_D.setFocusable(false);
bt2_D.setFocusable(false);
tf_D.setColumns(10);
bt1_D.setName("bt1_D");
bt2_D.setName("bt2_D");
combo_D.setName("combo_D");
tf_D.setName("tf_D");
panel_D.setOpaque(false);
panel_D.add(bt1_D);
panel_D.add(bt2_D);
panel_D.add(combo_D);
panel_D.add(tf_D);
}
return panel_D;
}
protected JPanel getComponentPanelE() {
if (panel_E == null) {
panel_E = new JPanel();
// WIP : si le panel n'est pas un focus cycle root alors
// il est impossible de lui appliquer la police de focus
panel_E.setFocusCycleRoot(true);
panel_E.setFocusTraversalPolicy(new LocalFocusPolicy());
bt1_E = new JButton("Button 1_E");
bt2_E = new JButton("Button 2_E");
combo_E = new JComboBox(months);
tf_E = new JTextField("tf_E");
tf_E.setColumns(10);
bt1_E.setName("bt1_E");
bt2_E.setName("bt2_E");
combo_E.setName("combo_E");
tf_E.setName("tf_E");
panel_E.setOpaque(false);
panel_E.add(bt1_E);
panel_E.add(bt2_E);
panel_E.add(combo_E);
panel_E.add(tf_E);
}
return panel_E;
}
class LocalFocusPolicy extends OFocusTraversalPolicy {
LocalFocusPolicy() {
super();
}
public Component getComponentAfter(Container focusCycleRoot, Component
aComponent) {
//PB : ne passe pas ici si le container n'est pas un focus cycle
root!
System.out.print(" - LocalFocusPolicy : AFTER :
"+aComponent.getName());
return super.getComponentAfter(focusCycleRoot, aComponent);
}
}
}
*************************** END Source OFocusDemo.java
**********************
************************* START OFocusTraversalPolicy.java
********************
import java.awt.*;
import javax.swing.*;
public class OFocusTraversalPolicy extends LayoutFocusTraversalPolicy {
public OFocusTraversalPolicy() {
super();
}
public Component getComponentAfter(Container focusCycleRoot, Component
aComponent) {
System.out.print(" - OFocusTraversalPolicy : AFTER :
"+aComponent.getName());
Component c;
if (aComponent == OFocusDemo.tf_B) {
c = OFocusDemo.tf_D;
}
else {
c = super.getComponentAfter(focusCycleRoot, aComponent);
}
System.out.println(" ==> "+c.getName());
return c;
}
public Component getComponentBefore(Container focusCycleRoot, Component
aComponent){
System.out.print(" - OFocusTraversalPolicy : BEFORE :
"+aComponent.getName());
Component c = super.getComponentBefore(focusCycleRoot, aComponent);
System.out.println(" ==> "+c.getName());
return c;
}
public Component getFirstComponent(Container focusCycleRoot) {
System.out.print(" - OFocusTraversalPolicy : FIRST :
"+focusCycleRoot.getName());
Component c = super.getFirstComponent(focusCycleRoot);
System.out.println(" ==> "+c.getName());
return c;
}
public Component getLastComponent(Container focusCycleRoot) {
System.out.print(" - OFocusTraversalPolicy : LAST :
"+focusCycleRoot.getName());
Component c = super.getLastComponent(focusCycleRoot);
System.out.println(" ==> "+c.getName());
return c;
}
protected boolean accept(Component aComponent) {
//System.out.println(" - OFocusTraversalPolicy : ACCEPT :
"+aComponent);
return super.accept(aComponent);
}
}
******************** END Source OFocusTraversalPolicy.java
**********************
Martin Hilpert schrieb:
> >
> > The answers point you to the documentation. That's helpful. I think
> > the problem is that the documentation isn't helping you very much and
> > I think that's because you're missing the point. You have to
> > _subclass_ FocusTraversalPolicy and implement the methods to do your
> > logic.
>
> oh great! i have to write a subclass! for each call of
> setNextFocusableComponent ...? that's a big regression - that's crazy! this
> would mean instead of calling one method for the last component of each
> mask, i have to write a (sub)class for each mask ... just to set the next
> focusable component ... that's not true, isn't it!
ey man, stop ranting, whining or shouting and start learning! Shannon
(and others) are perfectly right: you missed the point. What's so
difficult in subclassing a FocusTraversalPolicy, giving it a method
setSpecialNextFocusableComponentFor(Component comp, Component
specialComp), then let the policy return that specialComp whenever it is
asked to return the next after comp, then plugin your custom policy to
the correct container (probably what you call mask, here)? Once you have
done that it's exactly one method call as it was before - now to the
policy instead of the comp.
(Not that I would recommend it - the correct thing to do is analyze your
context and build a more general custom traversal policy)
And if you are totally unwilling to learn - keep using
setNextFocusableComponent, it's still working most of the time and
probably will do so for the life cycle of your application.
Greetings
Jeanette
"Kleopatra" <fast...@addcom.de> schrieb im Newsbeitrag
news:3C7B9EBA...@addcom.de...
Hmmm...Kleopatra seems to have gotten it as clear as day :)
> this is more complicated, needs extra classes, several lines of codes,
> bigger JAR files, ... THAT's the point! this is a regression and it's a step
Just because a method's deprecated doesn't mean its gone away. It
means that we recommend not using it any more in favor of a better
approach. It may dissapear some day when the new way is widely
adopted. But as of yet, we've never removed a deprecated method.
Obviously there's reason for this. We don't randomly deprecate things
to make you personally angry.
> backward. why did they deprecate setNextFocusableComponent()? if we don't
> care about deprecation, we could ignore them and they would be total
> meaningless. it's YOU that has to learn, because i just asked for a code
> replacement and you suggest that i should stick to the deprecated method.
That's right :) We did didn't we.
And that's because you were totally opposed to the idea of
subclassing. If you would stop your ranting for a minute and actually
read the new documentation, you'd see that the new way is just as
easy. First of all, you only need a _single_ policy. Then you plug it
in to the parent container. The parent then asks it for the next
component each time it needs to transfer focus. So, write a policy
that keeps an array of your components and who they should transfer
focus to next.
I apologize :)
I would like to help but I can't seem to understand what you're
asking. Why should your classes not be focus cycle roots?
Shannon
"Paul Boutie" <paulb...@yahoo.fr> wrote in message news:<a5fne2$gde$1...@wanadoo.fr>...
i've never said that!
> That's right :) We did didn't we.
> And that's because you were totally opposed to the idea of
> subclassing. If you would stop your ranting for a minute and actually
> read the new documentation, you'd see that the new way is just as
> easy.
i'm not opposed of subclassing. actually i love subclassing. just for your
info: i'm a Java developer for over 5 years now, and our last project uses
subclasses extensively.
> First of all, you only need a _single_ policy. Then you plug it
> in to the parent container. The parent then asks it for the next
> component each time it needs to transfer focus. So, write a policy
> that keeps an array of your components and who they should transfer
> focus to next.
what you don't see: you repeat yourself. so i have to follow: give an
example!
if i understand you correctly ("that keeps an array of your components"), i
have to create objects for each mask. i looked at the API: i can't find any
constructor or set() method to set "an array of components" to be cycled
through. i looked at DefaultFocusTraversalPolicy and it's super classes,
ContainerOrderFocusTraversalPolicy.
i'm still clueless ...
martin
okay i explains :
i'm working on a very big interface with plenty of classes who are often
differents classes.
I want to jump from panels to panels and not to be jailed like i am when i
define my panels as focus cycles roots.
And i am locked because can not define a custom traversal focus policy on a
panel who is not a focus cycle root.
i am wrong ?
thanks
"Shannon Hickey - Swing Team" <shan...@swingteam.com> wrote in message
news:bd02e3f4.02022...@posting.google.com...
>
> but doesn't really match my need, i want to define a focus cycle locally.
> Or maybe should navigate from a cycle root to another ???
Not sure that I understand what you want to achieve - looking at your
example (which I think is barely readable because it does not adhere to
Sun's coding conventions, by the way) it seems that you want to cycle
from the last component in the deepest down panel back to the first
component of the highest up panel (deep and high meaning in terms of
nested focusCycles) and at the same time have a local traversal policy
in the deepest panel. The following local policy will do so:
public Component getComponentAfter(Container focusCycleRoot,
Component aComponent) {
//PB : ne passe pas ici si le container n'est pas un focus cycle
//root!
Component last = getLastComponent(focusCycleRoot);
if (last == aComponent) {
return
getInitialComponent(SwingUtilities.getWindowAncestor(focusCycleRoot));
}
return super.getComponentAfter(focusCycleRoot, aComponent);
}
Basically, it's the local policies responsibility to decide which
component to focus before/next another one, that's especially important
if the other one is the first/last of the current focus cycle. Here your
custom policy has to decide if you want to move to another cycle or wrap
in the same cycle or do whatever. If you want to move into another
focusCycle, you'll have to do so explicitely in
getComponentAfter/getComponentBefore - the default implementations often
stay inside the current cycles, sometimes do a downCycle, but never (?)
an upCycle.
Greetings
Jeanette
Martin Hilpert wrote:
>
> "Shannon Hickey - Swing Team" <shan...@swingteam.com> schrieb im
> Newsbeitrag news:bd02e3f4.02022...@posting.google.com...
> > "Martin Hilpert" <martin....@dresdner-bank.com> wrote in message
> news:<a5g8iv$ed...@news-1.bank.dresdner.net>...
> > That's right :) We did didn't we.
> > And that's because you were totally opposed to the idea of
> > subclassing. If you would stop your ranting for a minute and actually
> > read the new documentation, you'd see that the new way is just as
> > easy.
>
> i'm not opposed of subclassing. actually i love subclassing. just for your
> info: i'm a Java developer for over 5 years now, and our last project uses
> subclasses extensively.
And you never implemented any own method into your subclasses? :)
> > First of all, you only need a _single_ policy. Then you plug it
> > in to the parent container. The parent then asks it for the next
> > component each time it needs to transfer focus. So, write a policy
> > that keeps an array of your components and who they should transfer
> > focus to next.
>
> what you don't see: you repeat yourself. so i have to follow: give an
> example!
look down...
> if i understand you correctly ("that keeps an array of your components"), i
> have to create objects for each mask. i looked at the API: i can't find any
> constructor or set() method to set "an array of components" to be cycled
> through. i looked at DefaultFocusTraversalPolicy and it's super classes,
> ContainerOrderFocusTraversalPolicy.
Subclass FocusTraversalPolicy and implement your own set-Method(s)!
> i'm still clueless ...
public class MyFocusTraversalPolicy extends FocusTraversalPolicy {
private Component[] componentCirclet = null;
// my own method to set the components that cycle focus
public void setComponentCirclet( Component[] components ) {
componentCirclet = components;
}
// implement the abstract methods from the superclass
// and use the circlet to decide which component has
// to be returned
public getFirstComponent( Container c ) {
return componentCirclet[0];
}
//...
}
I don't know what's so difficult. Sure, a Componentarray is not
a good example, but you can also use a Vector, Tree, Hashtable,
whatever...
HTH,
Gerhard