Java Code Examples for javax.swing.JTable#getSelectedRowCount()
The following examples show how to use
javax.swing.JTable#getSelectedRowCount() .
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: UIUtil.java From rest-client with Apache License 2.0 | 6 votes |
/** * @Title : rmRows * @Description: Remove selected rows * @Param : @param tab * @Param : @param tabMdl * @Return : void * @Throws : */ public static void rmRows(JTable tab, TabModel tabMdl) { int src = tab.getSelectedRowCount(); if (src < 1) { return; } String key = StringUtils.EMPTY; int[] rows = tab.getSelectedRows(); for (int i : rows) { key = tabMdl.getRowKey(i); RESTCache.getHists().remove(key); } tabMdl.deleteRow(rows); int rc = tabMdl.getRowCount(); for (int i = 0; i < rc; i++) { tabMdl.setValueAt(i + 1, i, 0); } }
Example 2
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 3
Source File: IKTaskSetPanel.java From opensim-gui with Apache License 2.0 | 6 votes |
public void valueChanged(ListSelectionEvent event) { if(event.getValueIsAdjusting()) return; // Update activeTable JTable otherTable = null; if(event.getSource()==ikMarkerTasksTable.getSelectionModel()) { activeTable = ikMarkerTasksTable; otherTable = ikCoordinateTasksTable; } else if(event.getSource()==ikCoordinateTasksTable.getSelectionModel()) { activeTable = ikCoordinateTasksTable; otherTable = ikMarkerTasksTable; } // Make sure only one table is selected at a time if(otherTable.getSelectedRowCount()>0) { otherTable.getSelectionModel().removeListSelectionListener(this); otherTable.getSelectionModel().clearSelection(); otherTable.getSelectionModel().addListSelectionListener(this); } // Update copy of selected rows selectedRows = activeTable.getSelectedRows().clone(); // TODO: if pending changes, might want to apply them to old selection updatePanel(); }
Example 4
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 5
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 6
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)); }
Example 7
Source File: HealthTab.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
@Override public void mouseClicked(MouseEvent e) { int fromRow = NO_ROW_SELECTED; JTable table; // RT MAX MIN SWITCH if (healthTableToDisplay == DISPLAY_RT) { table = rtTable; } else if (healthTableToDisplay == DISPLAY_MAX) { table = maxTable; } else { table = minTable; } // row is the one we clicked on int row = table.rowAtPoint(e.getPoint()); int col = table.columnAtPoint(e.getPoint()); if (e.isShiftDown()) { // from row is the first in the selection. It equals row if we clicked above the current selected row fromRow = table.getSelectedRow(); int n = table.getSelectedRowCount(); if (row == fromRow) fromRow = fromRow + n-1; } if (row >= 0 && col >= 0) { //Log.println("CLICKED ROW: "+row+ " and COL: " + col); displayRow(table, fromRow, row); } }
Example 8
Source File: ExperimentTab.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
public void mouseClicked(MouseEvent e) { int fromRow = NO_ROW_SELECTED; JTable table = null; if (showRawBytes.isSelected()) { table = this.table; } else { table = packetTable; } int row = table.rowAtPoint(e.getPoint()); int col = table.columnAtPoint(e.getPoint()); if (e.isShiftDown()) { // from row is the first in the selection. It equals row if we clicked above the current selected row fromRow = table.getSelectedRow(); int n = table.getSelectedRowCount(); if (row == fromRow) fromRow = fromRow + n-1; } if (row >= 0 && col >= 0) { //Log.println("CLICKED ROW: "+row+ " and COL: " + col); displayRow(table, fromRow, row); } }
Example 9
Source File: TableUtils.java From IrScrutinizer with GNU General Public License v3.0 | 5 votes |
public void tableMoveSelection(JTable table, boolean up) throws ErroneousSelectionException { barfIfNonconsecutiveSelection(table); int row = table.getSelectedRow(); int lastRow = row + table.getSelectedRowCount() - 1; if (row < 0) { guiUtils.error("No signal selected"); return; } DefaultTableModel tableModel = (DefaultTableModel) table.getModel(); if (up) { if (row == 0) { guiUtils.error("Cannot move up"); return; } } else { // down if (lastRow >= tableModel.getRowCount() - 1) { guiUtils.error("Cannot move down"); return; } } if (up) { tableModel.moveRow(row, lastRow, row - 1); table.addRowSelectionInterval(row - 1, row - 1); table.removeRowSelectionInterval(lastRow, lastRow); } else { tableModel.moveRow(row, lastRow, row + 1); table.addRowSelectionInterval(lastRow + 1, lastRow + 1); table.removeRowSelectionInterval(row, row); } }
Example 10
Source File: UIUtil.java From rest-client with Apache License 2.0 | 4 votes |
/** * @Title : move * @Description: Move up or down rows * @Param : @param tab * @Param : @param tabMdl * @Return : void * @Throws : */ public static void move(JTable tab, TabModel tabMdl, boolean isup) { int src = tab.getSelectedRowCount(); if (src < 1) { return; } HttpReq req = null; HttpRsp rsp = null; updateCache(); List<Entry<String, HttpHist>> es = new ArrayList<Entry<String,HttpHist>>(RESTCache.getHists().entrySet()); int[] row = tab.getSelectedRows(); if (isup) // Move up { mvup(es, row); } else // Move down { mvdown(es, row); } RESTCache.getHists().clear(); tabMdl.clear(); int i = 1; String key = StringUtils.EMPTY; for (Entry<String, HttpHist> e : es) { req = e.getValue().getReq(); rsp = e.getValue().getRsp(); key = tabMdl.insertRow(i, req.getMethod() + " " + req.getUrl(), rsp.getStatus(), rsp.getDate(), rsp.getTime() + "ms", e.getValue().getDescr()); RESTCache.getHists().put(key, e.getValue()); i++; } }
Example 11
Source File: EditSubmitActionListener.java From HBaseClient with GNU General Public License v3.0 | 4 votes |
@Override public void onClick(ActionEvent arg0) { HData v_HData = new HData(); v_HData.setRowKey( ((JTextComponent)XJava.getObject("Edit_RowKey")) .getText().trim()); v_HData.setFamilyName(((JComboBox) XJava.getObject("Edit_FamilyName")) .getSelectedItem().toString().trim()); v_HData.setColumnName(((JComboBox) XJava.getObject("Edit_ColumnName")) .getSelectedItem().toString().trim()); v_HData.setValue( ((JTextComponent)XJava.getObject("Edit_ColumnValue")).getText().trim()); if ( JavaHelp.isNull(v_HData.getRowKey()) ) { this.getAppFrame().showHintInfo("提交时,行主键不能为空!" ,Color.RED); ((JComponent)XJava.getObject("Edit_RowKey")).requestFocus(); return; } if ( JavaHelp.isNull(v_HData.getFamilyName()) ) { this.getAppFrame().showHintInfo("提交时,列族名不能为空!" ,Color.RED); ((JComponent)XJava.getObject("Edit_FamilyName")).requestFocus(); return; } if ( JavaHelp.isNull(v_HData.getColumnName()) ) { this.getAppFrame().showHintInfo("提交时,字段名不能为空!" ,Color.RED); ((JComponent)XJava.getObject("Edit_ColumnName")).requestFocus(); return; } try { HData v_OldHData = (HData)this.getHBase().getValue(this.getTableName() ,v_HData); this.getHBase().update(this.getTableName() ,v_HData); // 重新从数据库是查询一次,主要想获取时间戳 HData v_NewHData = (HData)this.getHBase().getValue(this.getTableName() ,v_HData); JTable v_JTable = (JTable)XJava.getObject("xtDataList"); int v_RowNo = v_JTable.getSelectedRow(); int v_OptType = 1; // 操作类型(0:修改 1:添加) if ( v_JTable.getSelectedRowCount() == 1 ) { if ( v_NewHData.getRowKey().equals(v_JTable.getValueAt(v_RowNo ,1)) ) { if ( v_NewHData.getFamilyName().equals(v_JTable.getValueAt(v_RowNo ,2)) ) { if ( v_NewHData.getColumnName().equals(v_JTable.getValueAt(v_RowNo ,3)) ) { v_OptType = 0; } } } } if ( v_OptType == 0 ) { v_JTable.setValueAt(v_NewHData.getValue().toString() ,v_RowNo ,4); v_JTable.setValueAt(v_NewHData.getTimestamp() ,v_RowNo ,5); v_JTable.setValueAt(v_NewHData.getTime().getFullMilli() ,v_RowNo ,6); this.getAppFrame().showHintInfo("修改完成!" ,Color.BLUE); } else { this.getAppFrame().setRowCount(this.getAppFrame().getRowCount() + 1); this.getAppFrame().getTableModel().addRow(SubmitActionListener.$MY.toObjects(this.getAppFrame().getRowCount() ,v_NewHData)); if ( v_OldHData != null ) { this.getAppFrame().showHintInfo("修改完成,请刷新查询结果。" ,Color.BLUE); } else { this.getAppFrame().showHintInfo("添加完成!" ,Color.BLUE); } } } catch (Exception exce) { this.getAppFrame().showHintInfo("修改异常:" + exce.getMessage() ,Color.RED); } }
Example 12
Source File: TableUtils.java From IrScrutinizer with GNU General Public License v3.0 | 4 votes |
private void barfIfManySelected(JTable table) throws ErroneousSelectionException { if (table.getSelectedRowCount() > 1) throw new ErroneousSelectionException("Only one row may be selected"); }