当前位置: 首页>>代码示例>>Java>>正文


Java JTable.getSelectedRowCount方法代码示例

本文整理汇总了Java中javax.swing.JTable.getSelectedRowCount方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.getSelectedRowCount方法的具体用法?Java JTable.getSelectedRowCount怎么用?Java JTable.getSelectedRowCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTable的用法示例。


在下文中一共展示了JTable.getSelectedRowCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copyToClipboard

import javax.swing.JTable; //导入方法依赖的package包/类
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);
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:39,代码来源:XTableUtils.java

示例2: updateCellRangeByTableSelection

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * 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));
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:11,代码来源:ExcelSheetSelectionPanelModel.java

示例3: copyToClipboard

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:47,代码来源:JtableUtils.java

示例4: importData

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public boolean importData(TransferHandler.TransferSupport info) {
   JTable target = (JTable) info.getComponent();
   JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation();
   int index = dl.getRow();
   int numSelected = table.getSelectedRowCount();
   int max = table.getModel().getRowCount();
   if (index + target.getSelectedRowCount() > max) return false;
   if (index < 0 || index > max)
      index = max;
   target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
   try {		    	  
      Integer rowFrom = (Integer) info.getTransferable().getTransferData(localObjectFlavor);
      if (rowFrom != -1 && rowFrom != index) {
         ((LineSegmentsObject)table.getModel()).reorder(rowFrom, index, numSelected);
      }
      //update the selected rows
      target.clearSelection();
      int index1 = index + numSelected - 1;
      target.addRowSelectionInterval(index, index1);

      return true; 
   } catch (Exception e) {
      e.printStackTrace();
   }
   return false;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:28,代码来源:Digitizer.java


注:本文中的javax.swing.JTable.getSelectedRowCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。