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


Java JTable.getSelectedColumns方法代码示例

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


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

示例1: pasteFromClipboard

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Reads clipboard data and converts it into supported format and fills the
 * tmodel cells
 *
 * @param table the target tmodel
 */
private static void pasteFromClipboard(JTable table) {
    int startRow = table.getSelectedRows()[0];
    int startCol = table.getSelectedColumns()[0];
    String pasteString;
    try {
        pasteString = (String) (CLIPBOARD.getContents(CLIPBOARD).getTransferData(DataFlavor.stringFlavor));
    } catch (UnsupportedFlavorException | IOException ex) {
        Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }
    String[] lines = pasteString.split(LINE_BREAK);
    for (int i = 0; i < lines.length; i++) {
        String[] cells = lines[i].split(CELL_BREAK);
        if (table.getRowCount() <= startRow + i) {
            ((DefaultTableModel) table.getModel()).addRow(nullRow);
        }
        for (int j = 0; j < cells.length; j++) {
            if (table.getColumnCount() > startCol + j) {
                if (table.isCellEditable(startRow + i, startCol + j)) {
                    table.setValueAt(cells[j], startRow + i, startCol + j);
                }
            }
        }
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:32,代码来源:JtableUtils.java

示例2: 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

示例3: createTransferable

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
protected Transferable createTransferable(JComponent source) {
    JTable table = (JTable) source;
    if (table.getModel() instanceof TestDataModel) {
        TestDataModel tdm = (TestDataModel) table.getModel();
        TestDataDetail td = new TestDataDetail();
        td.setSheetName(tdm.getName());
        for (int col : table.getSelectedColumns()) {
            if (col > 3) {
                td.getColumnNames().add(table.getColumnName(col));
            }
        }
        return new TransferableNode(td, DataFlavors.TESTDATA_FLAVOR);
    }
    return null;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:17,代码来源:TestDataDnD.java

示例4: createTransferable

import javax.swing.JTable; //导入方法依赖的package包/类
/******* Export Side *******/

	/* Create data from the selected rows and columns */
	@Override
	protected Transferable createTransferable(JComponent c)
	{
		JTable table = (JTable)c;
		rowsidx = table.getSelectedRows();
		colsidx = table.getSelectedColumns();

		Run store[][] = new Run[rowsidx.length][colsidx.length];
		for (int ii = 0; ii < rowsidx.length; ii++)
			for (int jj = 0; jj < colsidx.length; jj++)
				store[ii][jj] = (Run)table.getValueAt(rowsidx[ii], colsidx[jj]);

		return new SimpleDataTransfer(flavor, store);
	}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:18,代码来源:RunsTable.java

示例5: pasteFromAbove

import javax.swing.JTable; //导入方法依赖的package包/类
public static void pasteFromAbove(JTable table) {
    int startRow = table.getSelectedRows()[0];
    int[] cols = table.getSelectedColumns();
    for (int col : cols) {
        table.setValueAt(table.getValueAt(startRow - 1, col), startRow, col);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:8,代码来源:JtableUtils.java

示例6: ClearSelection

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * clear selection by setting empty values
 *
 * @param table to be cleared
 */
private static void ClearSelection(JTable table) {
    int[] srow = table.getSelectedRows();
    int[] scol = table.getSelectedColumns();
    int lastSrow = srow.length;
    int lastScol = scol.length;
    for (int i = 0; i < lastSrow; i++) {
        for (int j = 0; j < lastScol; j++) {
            if (table.isCellEditable(srow[i], scol[j])) {
                table.setValueAt("", srow[i], scol[j]);
            }
        }
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:19,代码来源:JtableUtils.java

示例7: 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

示例8: pasteFromClipboard

import javax.swing.JTable; //导入方法依赖的package包/类
public static void pasteFromClipboard(JTable table) {
    int startRow = table.getSelectedRows()[0];
    int startCol = table.getSelectedColumns()[0];

    String pasteString;
    try {
        pasteString = (String) (CLIPBOARD.getContents(null).getTransferData(DataFlavor.stringFlavor));
    } catch (Exception e) {
        Logger.getLogger(XTableUtils.class.getName()).log(Level.WARNING, "Invalid Paste Type", e);
        return;
    }
    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).startGroupEdit();
    }
    String[] lines = pasteString.split(LINE_BREAK);

    for (int i = 0; i < lines.length; i++) {
        String[] cells = lines[i].split(CELL_BREAK);
        for (int j = 0; j < cells.length; j++) {
            if (table.getRowCount() <= startRow + i) {
                if (table.getModel() instanceof DataModel) {
                    if (!((DataModel) table.getModel()).addRow()) {
                        return;
                    }
                }
            }
            if (table.getRowCount() > startRow + i && table.getColumnCount() > startCol + j) {
                table.setValueAt(cells[j], startRow + i, startCol + j);
            }
        }
    }
    if (table.getModel() instanceof UndoRedoModel) {
        ((UndoRedoModel) table.getModel()).stopGroupEdit();
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:36,代码来源:XTableUtils.java

示例9: getSelection

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


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