Java Code Examples for javax.swing.JTable#getRowSelectionAllowed()
The following examples show how to use
javax.swing.JTable#getRowSelectionAllowed() .
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: FlatTableCellBorder.java From FlatLaf with Apache License 2.0 | 6 votes |
/** * Checks whether at least one selected cell is editable. */ protected boolean isSelectionEditable( JTable table ) { if( table.getRowSelectionAllowed() ) { int columnCount = table.getColumnCount(); int[] selectedRows = table.getSelectedRows(); for( int selectedRow : selectedRows ) { for( int column = 0; column < columnCount; column++ ) { if( table.isCellEditable( selectedRow, column ) ) return true; } } } if( table.getColumnSelectionAllowed() ) { int rowCount = table.getRowCount(); int[] selectedColumns = table.getSelectedColumns(); for( int selectedColumn : selectedColumns ) { for( int row = 0; row < rowCount; row++ ) { if( table.isCellEditable( row, selectedColumn ) ) return true; } } } return false; }
Example 2
Source File: RTable.java From marathonv5 with Apache License 2.0 | 4 votes |
private String getSelection() { JTable table = (JTable) component; boolean rowSelectionAllowed = table.getRowSelectionAllowed(); boolean columnSelectionAllowed = table.getColumnSelectionAllowed(); if (!rowSelectionAllowed && !columnSelectionAllowed) { return null; } int[] rows = table.getSelectedRows(); int[] columns = table.getSelectedColumns(); int rowCount = table.getRowCount(); int columnCount = table.getColumnCount(); if (rows.length == rowCount && columns.length == columnCount) { return "all"; } if (rows.length == 0 && columns.length == 0) { return ""; } StringBuffer text = new StringBuffer(); text.append("rows:["); for (int i = 0; i < rows.length; i++) { text.append(rows[i]); if (i != rows.length - 1) { text.append(","); } } text.append("],"); text.append("columns:["); for (int i = 0; i < columns.length; i++) { String columnName = getColumnName(columns[i]); text.append(escape(columnName)); if (i != columns.length - 1) { text.append(","); } } text.append("]"); return text.toString(); }
Example 3
Source File: MenuManager.java From jeveassets with GNU General Public License v2.0 | 4 votes |
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); } } }
Example 4
Source File: CopyHandler.java From jeveassets with GNU General Public License v2.0 | 4 votes |
private static void copy(JTable jTable) { //Rows int[] rows; if (jTable.getRowSelectionAllowed()) { //Selected rows rows = jTable.getSelectedRows(); } else { //All rows (if row selection is not allowed) rows = new int[jTable.getRowCount()]; for (int i = 0; i < jTable.getRowCount(); i++) { rows[i] = i; } } //Columns int[] columns; if (jTable.getColumnSelectionAllowed()) { //Selected columns columns = jTable.getSelectedColumns(); } else { //All columns (if column selection is not allowed) columns = new int[jTable.getColumnCount()]; for (int i = 0; i < jTable.getColumnCount(); i++) { columns[i] = i; } } StringBuilder tableText = new StringBuilder(); //Table text buffer String separatorText = ""; //Separator text buffer (is never added to, only set for each separator) int rowCount = 0; //used to find last row for (int row : rows) { rowCount++; //count rows StringBuilder rowText = new StringBuilder(); //Row text buffer boolean firstColumn = true; //used to find first column for (int column : columns) { //Get value Object value = jTable.getValueAt(row, column); //Handle Separator if (value instanceof SeparatorList.Separator) { SeparatorList.Separator<?> separator = (SeparatorList.Separator) value; Object object = separator.first(); if (object instanceof CopySeparator) { CopySeparator copySeparator = (CopySeparator) object; separatorText = copySeparator.getCopyString(); } break; } //Add tab separator (except for first column) if (firstColumn) { firstColumn = false; } else { rowText.append("\t"); } //Add value if (value != null) { //Ignore null //Format value to displayed value if (value instanceof Float) { rowText.append(Formater.floatFormat(value)); } else if (value instanceof Double) { rowText.append(Formater.doubleFormat(value)); } else if (value instanceof Integer) { rowText.append(Formater.integerFormat(value)); } else if (value instanceof Long) { rowText.append(Formater.longFormat(value)); } else if (value instanceof Date) { rowText.append(Formater.columnDate(value)); } else if (value instanceof HierarchyColumn) { HierarchyColumn hierarchyColumn = (HierarchyColumn) value; rowText.append(hierarchyColumn.getExport()); } else { rowText.append(value.toString()); //Default } } } //Add if (rowText.length() > 0 || (!separatorText.isEmpty() && rowCount == rows.length)) { tableText.append(separatorText); //Add separator text (will be empty for normal tables) if (rowText.length() > 0 && !separatorText.isEmpty()) { //Add tab separator (if needed) tableText.append("\t"); } tableText.append(rowText.toString()); //Add row text (will be empty if only copying sinlge separator) if (rowCount != rows.length) { tableText.append("\r\n"); } //Add end line } } toClipboard(tableText.toString()); //Send it all to the clipboard }