本文整理匯總了Java中javax.swing.JTable.getSelectedColumnCount方法的典型用法代碼示例。如果您正苦於以下問題:Java JTable.getSelectedColumnCount方法的具體用法?Java JTable.getSelectedColumnCount怎麽用?Java JTable.getSelectedColumnCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.getSelectedColumnCount方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
示例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));
}
示例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);
}
}