Sort the step of focus with the Tab key in Java

1

I would like to know if anyone has any idea of how to order the passage of focus between the components of a panel? I already tried in this way and it did not give me results:

contentPane.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{
            btnInfoClientes, btnInfoClientesPep, btnInfoClienteEspe, btnInfoRubroEspe, btnInfoTransacciones, 
            btnInfoTransaccionesAmpl, btnInfoTransaccionesRec, btnInfoTransaccionesEnv, txtSucuTran, txtAno, 
            txtBoletaTran, btnBoleta, txtCodPersona, txtDocumento, txtNombre, txtApellido, btnBuscar}));

That would be the desired order, and as I read in some manuals, the setFocusTraversalPolicy method is one of the forms, but it does not follow the specified guidelines.

Another way I tried this method is also:

btnInfoClientes.setNextFocusableComponent(btnInfoClientesPep);

But apart from being deprecated the method, does not follow the desired route either.
I do not know if it would influence something, but the layout of my JPanel is Absolute:

contentPane.setLayout(null);
    
asked by Carlos 06.04.2017 в 17:18
source

1 answer

1

All containers in JSwing have a method that is setFocusTraversalPolicy .

It would be this for a panel this would be the code:

panel.setFocusTraversalPolicy(
new FocusTraversalOnArray(new Component[]{textField_4, textField_3}));

For a contentpane this would be the code:

contentPane.setFocusTraversalPolicy(
new FocusTraversalOnArray(new Component[]{textField, textField_2, textField_1}));

As you can see, in the order that you put your components, not only JTextField , it will be the tabulation order they have.

    
answered by 06.04.2017 в 17:41