Java Code Examples for javax.swing.JTable#scrollRectToVisible()

The following examples show how to use javax.swing.JTable#scrollRectToVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public void searchNext() {
	if (getViewerTab().getComponentCount() > 0) {
		if (_searchDlg != null) {
			ViewPane pane = ((Main) PacketSamurai.getUserInterface()).getViewerTab().getCurrentViewPane();
			if (pane != null) {
				int index = _searchDlg.search(pane.getSelectedPacketindex() + 1);
				if (index >= 0) {
					JTable pt = ((Main) PacketSamurai.getUserInterface()).getViewerTab().getCurrentViewPane().getPacketTable();
					pt.setAutoscrolls(true);
					pt.getSelectionModel().setSelectionInterval(index, index);
					pt.scrollRectToVisible(pt.getCellRect(index, 0, true));
					_searchDlg.setCurrentSearchIndex(index + 1);
				}
			}
		} else {
			toggleSearchDialog();
		}
	}
}
 
Example 2
Source File: TableSorter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setSelectedRow(JTable table, Object selectedObject, int objectColumn) {
    if(table==null || selectedObject==null || objectColumn==-1)return;
    //after move to java6 as minimum requirent for nb may consider to replace with JTable::convertRowIndexToModel and back
    //current mplementation works with java5
    TableModel model = table.getModel();
    int rowCount=table.getRowCount();
    for(int i=0; i<rowCount; i++) {
        if(selectedObject.equals(model.getValueAt(i, objectColumn))) {
            table.setRowSelectionInterval(i, i);
            table.scrollRectToVisible(table.getCellRect(i, objectColumn, true));
            break;
        }
    }
}
 
Example 3
Source File: JtableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts new row if any row is selected else adds new row at the end
 *
 * @param table
 */
public static void addrow(JTable table) {
    int rowindex = table.getRowCount();
    if (table.getSelectedRow() > -1) {
        ((DefaultTableModel) table.getModel()).addRow(nullRow);
        ((DefaultTableModel) table.getModel()).moveRow(table.getRowCount() - 1, table.getRowCount() - 1, table.getSelectedRow());
        rowindex = table.getSelectedRow();
    } else {
        ((DefaultTableModel) table.getModel()).addRow(nullRow);
    }
    table.scrollRectToVisible(new Rectangle(table.getCellRect(rowindex, 0, true)));
}
 
Example 4
Source File: TableUtils.java    From Zettelkasten with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method selects a certain row that contains the value {@code value}
 * in the column {@code column} in the jTable {@code table}.
 *
 * @param table the table where the row should be selected
 * @param value the value that should be selected
 * @param column the table-column that contains the value {@code value}.
 */
public static void selectValueInTable(JTable table, String value, int column) {
    for (int cnt = 0; cnt < table.getRowCount(); cnt++) {
        String val = table.getValueAt(cnt, column).toString();
        if (val.equals(value)) {
            table.getSelectionModel().setSelectionInterval(cnt, cnt);
            table.scrollRectToVisible(table.getCellRect(cnt, column, false));
            // and leave method
            return;
        }
    }
}
 
Example 5
Source File: TableUtils.java    From Zettelkasten with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method retrieves the key-code {@code keyCode} of a released key in
 * the JTable {@code table} and checks whether this key was a navigation key
 * (i.e. cursor up/down/left/right or home/end). If so, the method tries to
 * select the next related entry of that JTable, according to the pressed
 * key.<br><br>
 * Furthermore, the related content is made visible (scroll rect to visible
 * or ensure index is visible).
 *
 * @param table a reference to the JTable where the related key was released
 * @param keyCode the keycode of the released key
 */
public static void navigateThroughList(JTable table, int keyCode) {
    if (KeyEvent.VK_LEFT == keyCode || KeyEvent.VK_RIGHT == keyCode) {
        return;
    }
    int selectedRow = table.getSelectedRow();
    if (-1 == selectedRow) {
        selectedRow = 0;
    }
    switch (keyCode) {
        case KeyEvent.VK_HOME:
            selectedRow = 0;
            break;
        case KeyEvent.VK_END:
            selectedRow = table.getRowCount() - 1;
            break;
        case KeyEvent.VK_DOWN:
            if (table.getRowCount() > (selectedRow + 1)) {
                selectedRow++;
            }
            break;
        case KeyEvent.VK_UP:
            if (selectedRow > 0) {
                selectedRow--;
            }
            break;
    }
    table.getSelectionModel().setSelectionInterval(selectedRow, selectedRow);
    table.scrollRectToVisible(table.getCellRect(selectedRow, 0, false));
}
 
Example 6
Source File: TableUtils.java    From Zettelkasten with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method selects the first entry in the JTable {@code table} that
 * start with the text that is entered in the filter-textfield
 * {@code textfield}.
 *
 * @param table the jTable where the item should be selected
 * @param textfield the related filtertextfield that contains the user-input
 * @param column the column where the filtering-comparison should be applied
 * to. in most cases, the relevant information (i.e. the string/text) is in
 * column 0, but sometimes also in column 1
 */
public static void selectByTyping(JTable table, javax.swing.JTextField textfield, int column) {
    String text = textfield.getText().toLowerCase();
    for (int cnt = 0; cnt < table.getRowCount(); cnt++) {
        String val = table.getValueAt(cnt, column).toString();
        if (val.toLowerCase().startsWith(text)) {
            table.getSelectionModel().setSelectionInterval(cnt, cnt);
            table.scrollRectToVisible(table.getCellRect(cnt, column, false));
            // and leave method
            return;
        }
    }
}
 
Example 7
Source File: PathnameTableModel.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void notifyDataChanged(JTable table, int newIndex) {
	fireTableDataChanged();
	table.setRowSelectionInterval(newIndex, newIndex);
	Rectangle rect = table.getCellRect(newIndex, 0, true);
	table.scrollRectToVisible(rect);
}
 
Example 8
Source File: SwingUtil.java    From Repeat with Apache License 2.0 4 votes vote down vote up
public static void scrollToSelectedRow(JTable table) {
	int selectedRow = table.getSelectedRow();
	table.scrollRectToVisible(table.getCellRect(selectedRow, 0, true));
}