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