Java - Seleccionar el texto de una celda en un jtable al hacer tab

 
Vista:
sin imagen de perfil

Seleccionar el texto de una celda en un jtable al hacer tab

Publicado por rocio (2 intervenciones) el 03/02/2017 21:48:54
Buenas Tardes,

Aun no tengo mucha experiencia en esto, Necesito seleccionar el texto de una celda en una jtable como se muestra a continuación:

ima1

por el momento solo he logrado seleccionar toda la celda en si, de la siguiente manera:

ima2

con la ayuda de este código que encontré en otro foro:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public class Prueba extends javax.swing.JFrame {
 
    public Prueba() {
        initComponents();
        setLocationRelativeTo(this);
 
 
        tbPrueba.getSelectionModel().addListSelectionListener(new RowListener());
        tbPrueba.getColumnModel().getSelectionModel().addListSelectionListener(new ColumnListener());
    }
 
    private class RowListener implements ListSelectionListener {
 
        public void valueChanged(ListSelectionEvent event) {
 
            if (true) {
                tbPrueba.setCellSelectionEnabled(true);
            }
            if (event.getValueIsAdjusting()){
                return;
            }
            try{outputSelection();}
            catch(SQLException o){o.printStackTrace();  }
      }
    }
    private class ColumnListener implements ListSelectionListener {
 
        public void valueChanged(ListSelectionEvent event) {
            if (event.getValueIsAdjusting()) {
                return;
            }//System.out.println("columnas");
            try{outputSelection();}
            catch(SQLException o){o.printStackTrace();  }
        }
    }
   private void outputSelection()throws  SQLException{
 
        int f,c;
 
        f=tbPrueba.getSelectionModel().getLeadSelectionIndex();
        c=tbPrueba.getColumnModel().getSelectionModel().getLeadSelectionIndex();
       Object oProducto=tbPrueba.getModel().getValueAt(f,c);
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Seleccionar el texto de una celda en un jtable al hacer tab

Publicado por rocio (2 intervenciones) el 28/02/2017 16:19:36
Alguna ayuda o sugerencia??
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar