Java - tabla

 
Vista:

tabla

Publicado por zpyrt (58 intervenciones) el 08/07/2005 16:52:07
como puedo hacer para que cuando inserto una fila en una tabla, se haga un scroll hasta la fila insertada, que vendria siendo la ultima.
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
Val: 755
Bronce
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

RE:tabla

Publicado por Yamil Bracho (2315 intervenciones) el 08/07/2005 20:51:00
Esto lo consegui en el Java Almanac:

// Ensure that the cell (1,2) is visible
int rowIndex = 1;
int vColIndex = 2;
scrollToVisible(table, rowIndex, vColIndex);

// Assumes table is contained in a JScrollPane. Scrolls the
// cell (rowIndex, vColIndex) so that it is visible within the viewport.
public void scrollToVisible(JTable table, int rowIndex, int vColIndex) {
if (!(table.getParent() instanceof JViewport)) {
return;
}
JViewport viewport = (JViewport)table.getParent();

// This rectangle is relative to the table where the
// northwest corner of cell (0,0) is always (0,0).
Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);

// The location of the viewport relative to the table
Point pt = viewport.getViewPosition();

// Translate the cell location so that it is relative
// to the view, assuming the northwest corner of the
// view is (0,0)
rect.setLocation(rect.x-pt.x, rect.y-pt.y);

// Scroll the area into view
viewport.scrollRectToVisible(rect);

Related Examples

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