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:
por el momento solo he logrado seleccionar toda la celda en si, de la siguiente manera:
con la ayuda de este código que encontré en otro foro:
Aun no tengo mucha experiencia en esto, Necesito seleccionar el texto de una celda en una jtable como se muestra a continuación:
por el momento solo he logrado seleccionar toda la celda en si, de la siguiente manera:
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
0