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

The following examples show how to use javax.swing.JTable#setColumnSelectionInterval() . 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: SwingUtil.java    From Repeat with Apache License 2.0 4 votes vote down vote up
public static void highLightCell(JTable table, int row, int column) {
	table.setRowSelectionInterval(row, row);
	table.setColumnSelectionInterval(column, column);
	scrollToSelectedRow(table);
}
 
Example 2
Source File: SwingUtil.java    From Repeat with Apache License 2.0 4 votes vote down vote up
public static void focusRowTable(JTable table, int row) {
	table.setRowSelectionInterval(row, row);
	table.setColumnSelectionInterval(0, table.getColumnCount() - 1);
	scrollToSelectedRow(table);
}
 
Example 3
Source File: SwingUtil.java    From Repeat with Apache License 2.0 4 votes vote down vote up
public static void focusColumnTable(JTable table, int column) {
	table.setColumnSelectionInterval(column, column);
	table.setRowSelectionInterval(0, table.getColumnCount() - 1);
}
 
Example 4
Source File: SwingUtil.java    From Repeat with Apache License 2.0 4 votes vote down vote up
public static void focusCellTable(JTable table, int row, int column) {
	table.setRowSelectionInterval(row, row);
	table.setColumnSelectionInterval(column, column);
}
 
Example 5
Source File: MenuManager.java    From jeveassets with GNU General Public License v2.0 4 votes vote down vote up
private void selectClickedCell(final MouseEvent e) {
	Object source = e.getSource();
	if (source instanceof JTable) {
		JTable jSelectTable = (JTable) source;

		Point point = e.getPoint();
		if (!jSelectTable.getVisibleRect().contains(point)) { //Ignore clickes outside table
			return;
		}

		int clickedRow = jSelectTable.rowAtPoint(point);
		int clickedColumn = jSelectTable.columnAtPoint(point);

		//Rows
		boolean clickInRowsSelection;
		if (jSelectTable.getRowSelectionAllowed()) { //clicked in selected rows?
			clickInRowsSelection = false;
			int[] selectedRows = jSelectTable.getSelectedRows();
			for (int i = 0; i < selectedRows.length; i++) {
				if (selectedRows[i] == clickedRow) {
					clickInRowsSelection = true;
					break;
				}
			}
		} else { //Row selection not allowed - all rows selected
			clickInRowsSelection = true;
		}

		//Column
		boolean clickInColumnsSelection;
		if (jSelectTable.getColumnSelectionAllowed()) { //clicked in selected columns?
			clickInColumnsSelection = false;
			int[] selectedColumns = jSelectTable.getSelectedColumns();
			for (int i = 0; i < selectedColumns.length; i++) {
				if (selectedColumns[i] == clickedColumn) {
					clickInColumnsSelection = true;
					break;
				}
			}
		} else { //Column selection not allowed - all columns selected
			clickInColumnsSelection = true;
		}

		//Clicked outside selection, select clicked cell
		if ( (!clickInRowsSelection || !clickInColumnsSelection) && clickedRow >= 0 && clickedColumn >= 0) {
			jSelectTable.setRowSelectionInterval(clickedRow, clickedRow);
			jSelectTable.setColumnSelectionInterval(clickedColumn, clickedColumn);
		}
	}
}