當前位置: 首頁>>代碼示例>>Java>>正文


Java JTable.setValueAt方法代碼示例

本文整理匯總了Java中javax.swing.JTable.setValueAt方法的典型用法代碼示例。如果您正苦於以下問題:Java JTable.setValueAt方法的具體用法?Java JTable.setValueAt怎麽用?Java JTable.setValueAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JTable的用法示例。


在下文中一共展示了JTable.setValueAt方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getEncryptAction

import javax.swing.JTable; //導入方法依賴的package包/類
private static AbstractAction getEncryptAction(final JTable table) {
    return new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent me) {
            try {
                int col = table.getSelectedColumn();
                int row = table.getSelectedRow();
                if (col > -1 && row > -1) {
                    String data = table.getValueAt(row, col).toString();
                    table.setValueAt(TMIntegration.encrypt(data), row, col);
                }
            } catch (HeadlessException ex) {
                Logger.getLogger(TMSettingsControl.class.getName())
                        .log(Level.SEVERE, ex.getMessage(), ex);
            }

        }
    };
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:20,代碼來源:TMSettingsControl.java

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

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

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

示例7: emptyTable

import javax.swing.JTable; //導入方法依賴的package包/類
public static void emptyTable(JTable table, int column) {
    for (int i = 0; i < table.getRowCount(); i++) {
        for (int j = 0; j < table.getColumnCount(); j++) {
            try {
                if (column != j) {
                    table.setValueAt(null, i, j);
                }
            } catch (Exception ex) {
                Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:14,代碼來源: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: mouseReleased

import javax.swing.JTable; //導入方法依賴的package包/類
@Override
public void mouseReleased(MouseEvent e) {
    if (startLocation != null && isInDragOperation) {
        Object s = e.getSource();
        JTable t = (JTable) s;
        for (Integer[] index : rowsRColumns) {
            t.setValueAt(startLocation.getData(), index[0], index[1]);
        }
        startLocation = null;
    }
    rowsRColumns.clear();
    isInDragOperation = false;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:14,代碼來源:TableCellDrag.java

示例10: putTestData

import javax.swing.JTable; //導入方法依賴的package包/類
private void putTestData(JTable table, int row) {
    TestCase testCase = (TestCase) table.getModel();
    testCase.startGroupEdit();
    TestDataDetail td = (TestDataDetail) dropObject;
    for (String col : td.getColumnNames()) {
        if (row > table.getRowCount() - 1) {
            testCase.addNewStep();
        }
        table.setValueAt(td.getSheetName() + ":" + col, row++, inputColumn);
    }
    testCase.stopGroupEdit();
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:13,代碼來源:TestCaseTableDnD.java

示例11: importData

import javax.swing.JTable; //導入方法依賴的package包/類
@Override
public boolean importData(TransferHandler.TransferSupport support)
{
	try
	{
		Run newdata[][] = (Run[][])support.getTransferable().getTransferData(flavor);
		JTable target = (JTable)support.getComponent();
		int dr,dc;

		if (!support.isDrop())
		{
			/* Set the data */
			dr = target.getSelectedRow();
			dc = target.getSelectedColumn();

			for (int ii = 0; ii < newdata.length; ii++)
				for (int jj = 0; jj < newdata[0].length; jj++)
					target.setValueAt((newdata[ii][jj]).clone(), dr+ii, dc+jj);
		}

		return true;
	}
	catch (UnsupportedFlavorException ufe) { log.warning("Sorry, you pasted data I don't work with"); }
	catch (IOException ioe) { log.log(Level.WARNING, "I/O Error during paste:{0}", ioe.getMessage()); }
	catch (Exception e) { log.log(Level.WARNING, "General error during paste:{0}", e.getMessage()); }

	return false;
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:29,代碼來源:RunsTable.java

示例12: putRelativeObject

import javax.swing.JTable; //導入方法依賴的package包/類
private void putRelativeObject(JTable table, int row) {
    String val = ((ObjectRepDnD) dropObject).getObjectName(((ObjectRepDnD) dropObject).getValues().get(0));
    if (val != null) {
        table.setValueAt(val, row, conditionColumn);
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:7,代碼來源:TestCaseTableDnD.java

示例13: putInput

import javax.swing.JTable; //導入方法依賴的package包/類
private void putInput(JTable table, int row) {
    table.setValueAt("@" + ((ObjectRepDnD) dropObject).getPageName(((ObjectRepDnD) dropObject).getValues().get(0)), row, inputColumn);
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:4,代碼來源:TestCaseTableDnD.java


注:本文中的javax.swing.JTable.setValueAt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。