Utilisation de FocusTraversalPolicy

kissmytoe Messages postés 9 Date d'inscription lundi 30 août 2004 Statut Membre Dernière intervention 19 avril 2005 - 19 avril 2005 à 16:54
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 - 20 avril 2005 à 08:55
J'ai fait un petit programme et j'aimerais bien que le focus fonctionne. J'ai recherché un tas d'example de la classe FocusTraversalPolicy pour essayé de faire fonctionner ceci... Mais rien ne fonctionne....

private JTextField coteA = new JTextField();
private JTextField coteB = new JTextField();
private JTextField coteC = new JTextField(); private JLabel jLabel1 new JLabel(); private JLabel jLabel2 new JLabel();
private JLabel jLabel3 = new JLabel();
private JButton btnValider = new JButton();
private JButton btnEffacer = new JButton();
private JButton btnQuitter = new JButton();
private JLabel rep = new JLabel();
private JPanel jPanel1 = new JPanel();
private JLabel repTexte = new JLabel();
private JLabel repImage = new JLabel();
private String A, B, C;
private Triangle triangle;
private String typeTriangle;
final TravPolicyA policyA = new TravPolicyA();

...

this.getContentPane().setFocusTraversalPolicy(policyA);

...

public class TravPolicyA extends FocusTraversalPolicy
{
public Component getDefaultComponent(Container focusCycleRoot)
{
return coteA;
}
public Component getFirstComponent(Container focusCycleRoot)
{
return coteA;
}
public Component getLastComponent(Container focusCycleRoot)
{
return btnQuitter;
}
public Component getComponentAfter(Container focusCycleRoot,
Component aComponent)
{
if(aComponent == coteA){
return coteB;
}
else if(aComponent == coteB)
{
return coteC;
}
else if(aComponent == coteC)
{
return btnValider;
}
else if(aComponent == btnValider)
{
return btnEffacer;
}
else if(aComponent == btnEffacer)
{
return btnQuitter;
}
else if(aComponent == btnQuitter)
{
return coteA;
}
return coteA;
}
public Component getComponentBefore(Container focusCycleRoot,
Component aComponent)
{
if(aComponent == coteA)
{
return btnQuitter;
}
else if(aComponent == coteB)
{
return coteA;
}
else if(aComponent == coteC)
{
return coteB;
}
else if(aComponent == btnValider)
{
return coteC;
}
else if(aComponent == btnEffacer)
{
return btnValider;
}
else if(aComponent == btnQuitter)
{
return btnEffacer;
}
return coteA;
}
}

MaRy

1 réponse

Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
20 avril 2005 à 08:55
Salut,

dsl mais perso je n'ai jamais utilisé cette objet mais cependant après
5minutes de google (recherche = FocusTraversalPolicy+sample)
je t'ai trouvé ça




http://www-106.ibm.com/developerworks/java/library/j-mer07153/

cette page contient une explication et un code source d'exemple




WORA
0
Rejoignez-nous