Java Code Examples for javax.swing.JTable#getSelectedColumnCount()
The following examples show how to use
javax.swing.JTable#getSelectedColumnCount() .
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: FilterControl.java From jeveassets with GNU General Public License v2.0 | 6 votes |
public JMenu getMenu(final JTable jTable, final List<E> items) { String text = null; EnumTableColumn<?> column = null; boolean isNumeric = false; boolean isDate = false; int columnIndex = jTable.getSelectedColumn(); if (jTable.getSelectedColumnCount() == 1 //Single cell (column) && jTable.getSelectedRowCount() == 1 //Single cell (row) && items.size() == 1 //Single element && !(items.get(0) instanceof SeparatorList.Separator) //Not Separator && columnIndex >= 0 //Shown column && columnIndex < getShownColumns().size()) { //Shown column column = getShownColumns().get(columnIndex); isNumeric = isNumeric(column); isDate = isDate(column); text = FilterMatcher.format(getColumnValue(items.get(0), column.name()), false); } return new FilterMenu<E>(gui, column, text, isNumeric, isDate); }
Example 2
Source File: JtableUtils.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
/** * Reads the cell values of selected cells of the <code>tmodel</code> and * uploads into clipboard in supported format * * @param isCut CUT flag,<code>true</code> for CUT and <code>false</code> * for COPY * @param table the source for the action * @see #escape(java.lang.Object) */ private static void copyToClipboard(boolean isCut, JTable table) { try { int numCols = table.getSelectedColumnCount(); int numRows = table.getSelectedRowCount(); int[] rowsSelected = table.getSelectedRows(); int[] colsSelected = table.getSelectedColumns(); if (numRows != rowsSelected[rowsSelected.length - 1] - rowsSelected[0] + 1 || numRows != rowsSelected.length || numCols != colsSelected[colsSelected.length - 1] - colsSelected[0] + 1 || numCols != colsSelected.length) { JOptionPane.showMessageDialog(null, "Invalid Selection", "Invalid Selection", JOptionPane.ERROR_MESSAGE); return; } StringBuilder excelStr = new StringBuilder(); for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) { excelStr.append(escape(table.getValueAt(rowsSelected[i], colsSelected[j]))); if (isCut) { if (table.isCellEditable(rowsSelected[i], colsSelected[j])) { table.setValueAt("", rowsSelected[i], colsSelected[j]); } } if (j < numCols - 1) { excelStr.append(CELL_BREAK); } } if (i < numRows - 1) { excelStr.append(LINE_BREAK); } } if (!excelStr.toString().isEmpty()) { StringSelection sel = new StringSelection(excelStr.toString()); CLIPBOARD.setContents(sel, sel); } } catch (HeadlessException ex) { Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex); } }
Example 3
Source File: XTableUtils.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
public static void copyToClipboard(JTable table, boolean isCut) { int numCols = table.getSelectedColumnCount(); int numRows = table.getSelectedRowCount(); int[] rowsSelected = table.getSelectedRows(); int[] colsSelected = table.getSelectedColumns(); if (numRows != rowsSelected[rowsSelected.length - 1] - rowsSelected[0] + 1 || numRows != rowsSelected.length || numCols != colsSelected[colsSelected.length - 1] - colsSelected[0] + 1 || numCols != colsSelected.length) { Logger.getLogger(XTableUtils.class.getName()).info("Invalid Copy Selection"); return; } if (table.getModel() instanceof UndoRedoModel) { ((UndoRedoModel) table.getModel()).startGroupEdit(); } StringBuilder excelStr = new StringBuilder(); for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) { excelStr.append(escape(table.getValueAt(rowsSelected[i], colsSelected[j]))); if (isCut) { table.setValueAt("", rowsSelected[i], colsSelected[j]); } if (j < numCols - 1) { excelStr.append(CELL_BREAK); } } excelStr.append(LINE_BREAK); } if (table.getModel() instanceof UndoRedoModel) { ((UndoRedoModel) table.getModel()).stopGroupEdit(); } StringSelection sel = new StringSelection(excelStr.toString()); CLIPBOARD.setContents(sel, sel); }
Example 4
Source File: ExcelSheetSelectionPanelModel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Uses the current table selection to update the cell range selection. */ void updateCellRangeByTableSelection(JTable contentTable) { int columnIndexStart = contentTable.getSelectedColumn(); int rowIndexStart = contentTable.getSelectedRow(); int columnIndexEnd = columnIndexStart + contentTable.getSelectedColumnCount() - 1; int rowIndexEnd = rowIndexStart + contentTable.getSelectedRowCount() - 1; setCellRangeSelection(new CellRangeSelection(columnIndexStart, rowIndexStart, columnIndexEnd, rowIndexEnd)); }