Here you can find the source of fireTableDataChangedAndKeepSelection(final AbstractTableModel tableModel, final JTable table)
Parameter | Description |
---|---|
tableModel | DOCUMENT ME! |
table | DOCUMENT ME! |
public static void fireTableDataChangedAndKeepSelection(final AbstractTableModel tableModel, final JTable table)
//package com.java2s; //License from project: Open Source License import javax.swing.JTable; import javax.swing.SwingUtilities; import javax.swing.table.AbstractTableModel; public class Main { /**/*ww w.j ava 2s.c o m*/ * DOCUMENT ME! * * @param tableModel DOCUMENT ME! * @param table DOCUMENT ME! */ public static void fireTableDataChangedAndKeepSelection(final AbstractTableModel tableModel, final JTable table) { final int selection_view = table.getSelectedRow(); int selection_model_tmp = -1; if (selection_view > -1) { selection_model_tmp = table.convertRowIndexToModel(selection_view); } final int selection_model = selection_model_tmp; tableModel.fireTableDataChanged(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if ((selection_view == -1) || (selection_view >= table.getRowCount())) { table.clearSelection(); } else { final int selection_view_tmp = table.convertRowIndexToView(selection_model); table.setRowSelectionInterval(selection_view_tmp, selection_view_tmp); table.scrollRectToVisible(table.getCellRect(selection_view_tmp, 0, true)); } } }); } }