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


Java JTable.isCellEditable方法代码示例

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


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

示例1: validate

import javax.swing.JTable; //导入方法依赖的package包/类
private void validate(int viewRow, int viewCol) {
    JTable table = (JTable) getComponent();
    try {
        int row = table.convertRowIndexToModel(viewRow);
        int col = table.convertColumnIndexToModel(viewCol);
        TableModel model = table.getModel();
        if (row >= 0 && row < model.getRowCount() && col >= 0 && col < model.getColumnCount()) {
            if (table.isCellEditable(viewRow, viewCol)) {
                return;
            } else {
                throw new NoSuchElementException("The cell is not editable on JTable: (" + viewRow + ", " + viewCol + ")",
                        null);
            }
        }
    } catch (IndexOutOfBoundsException e) {
    }
    throw new NoSuchElementException("Invalid row/col for JTable: (" + viewRow + ", " + viewCol + ")", null);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:JTableJavaElement.java

示例2: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	if (table.isCellEditable(row, column)) {
		button.setEnabled(true);
	} else {
		button.setEnabled(false);
	}
	return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:10,代码来源:FiringSectionPanel.java

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

示例4: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	if (!table.isCellEditable(row, column)) {
		disableRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		disableRenderer.setHorizontalAlignment(SwingConstants.LEFT);
		return disableRenderer;
	} else {
		return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	}
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:11,代码来源:InputSectionPanel.java

示例5: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	if (!table.isCellEditable(row, column)) {
		return label;
	}
	return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:8,代码来源:StorageSectionPanel.java

示例6: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
	Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
	super.setHorizontalAlignment(SwingConstants.LEFT);
	if (!table.isCellEditable(row, 1)) {
		renderer.setEnabled(false);
	} else {
		renderer.setEnabled(true);
	}
	return renderer;
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:12,代码来源:RoutingSectionPanel.java

示例7: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
	super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
	if (value instanceof String && ("\u221e".equals(value) || "--".equals(value))) {
		setHorizontalAlignment(SwingConstants.RIGHT);
	}
	if (!table.isCellEditable(row, col)) {
		setEnabled(false);
	} else {
		setEnabled(true);
	}
	return this;
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:14,代码来源:GrayCellRenderer.java

示例8: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	if (!table.isCellEditable(row, referenceColumn))
		renderer.setEnabled(false);
	return renderer;

}
 
开发者ID:max6cn,项目名称:jmt,代码行数:9,代码来源:ImagedComboBoxCellEditorFactory.java

示例9: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
	Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);

	// Paints infinity symbol as a number
	if (value instanceof String && "\u221E".equals(value)) {
		super.setHorizontalAlignment(SwingConstants.RIGHT);
	}
	if (!table.isCellEditable(row, col)) {
		renderer.setEnabled(false);
	} else {
		renderer.setEnabled(true);
	}
	return renderer;
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:16,代码来源:GrayCellRenderer.java

示例10: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Returns the component used for drawing the cell.  This method is
 * used to configure the renderer appropriately before drawing.
 *
 * @param    table        the <code>JTable</code> that is asking the
 * renderer to draw; can be <code>null</code>
 * @param    value        the value of the cell to be rendered.  It is
 * up to the specific renderer to interpret
 * and draw the value.  For example, if
 * <code>value</code>
 * is the string "true", it could be rendered as a
 * string or it could be rendered as a check
 * box that is checked.  <code>null</code> is a
 * valid value
 * @param    isSelected    true if the cell is to be rendered with the
 * selection highlighted; otherwise false
 * @param    hasFocus    if true, render cell appropriately.  For
 * example, put a special border on the cell, if
 * the cell can be edited, render in the color used
 * to indicate editing
 * @param    row     the row index of the cell being drawn.  When
 * drawing the header, the value of
 * <code>row</code> is -1
 * @param    column     the column index of the cell being drawn
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	Component renderer = getDrawComponent(value);
	if (table.isCellEditable(row, column)) {
		// If the cell is editable, returns a comboBox
		combo.removeAllItems();
		if (value != null) {
			combo.addItem(renderer);
			combo.setSelectedItem(value);
		}
		if (!isSelected) {
			combo.setBackground(table.getBackground());
			combo.setForeground(table.getForeground());
		} else {
			combo.setBackground(table.getSelectionBackground());
			combo.setForeground(table.getSelectionForeground());
		}
		return combo;
	} else {
		// Otherwise returns the label only.
		if (!isSelected) {
			renderer.setBackground(table.getBackground());
			renderer.setForeground(table.getForeground());
		} else {
			renderer.setBackground(table.getSelectionBackground());
			renderer.setForeground(table.getSelectionForeground());
		}
		return renderer;
	}
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:55,代码来源:ImagedComboBoxCellEditorFactory.java

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

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

示例13: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Returns the component used for drawing the cell.  This method is
 * used to configure the renderer appropriately before drawing.
 *
 * @param    table        the <code>JTable</code> that is asking the
 * renderer to draw; can be <code>null</code>
 * @param    value        the value of the cell to be rendered.  It is
 * up to the specific renderer to interpret
 * and draw the value.  For example, if
 * <code>value</code>
 * is the string "true", it could be rendered as a
 * string or it could be rendered as a check
 * box that is checked.  <code>null</code> is a
 * valid value
 * @param    isSelected    true if the cell is to be rendered with the
 * selection highlighted; false otherwise
 * @param    hasFocus    if true, render cell appropriately.  For
 * example, put a special border on the cell, if
 * the cell can be edited, render in the color used
 * to indicate editing
 * @param    row     the row index of the cell being drawn.  When
 * drawing the header, the value of
 * <code>row</code> is -1
 * @param    column     the column index of the cell being drawn
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	// If cell is not editable, returns standard renderer
	if (!table.isCellEditable(row, column)) {
		return table.getDefaultRenderer(value.getClass()).getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	}

	comboBox.removeAllItems();
	if (value != null) {
		comboBox.addItem(value);
		comboBox.setSelectedItem(value);
	}
	if (!isSelected) {
		comboBox.setBackground(table.getBackground());
		comboBox.setForeground(table.getForeground());
	} else {
		comboBox.setBackground(table.getSelectionBackground());
		comboBox.setForeground(table.getSelectionForeground());
	}
	return comboBox;
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:46,代码来源:ComboBoxCellEditor.java

示例14: getTableCellRendererComponent

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Returns the component used for drawing the cell.  This method is
 * used to configure the renderer appropriately before drawing.
 *
 * @param    table        the <code>JTable</code> that is asking the
 * renderer to draw; can be <code>null</code>
 * @param    value        the value of the cell to be rendered.  It is
 * up to the specific renderer to interpret
 * and draw the value.  For example, if
 * <code>value</code>
 * is the string "true", it could be rendered as a
 * string or it could be rendered as a check
 * box that is checked.  <code>null</code> is a
 * valid value
 * @param    isSelected    true if the cell is to be rendered with the
 * selection highlighted; otherwise false
 * @param    hasFocus    if true, render cell appropriately.  For
 * example, put a special border on the cell, if
 * the cell can be edited, render in the color used
 * to indicate editing
 * @param    row     the row index of the cell being drawn.  When
 * drawing the header, the value of
 * <code>row</code> is -1
 * @param    column     the column index of the cell being drawn
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	// If cell is not editable, returns standard renderer
	if (!table.isCellEditable(row, column)) {
		return table.getDefaultRenderer(value.getClass()).getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	}

	comboBox.removeAllItems();
	if (value != null) {
		comboBox.addItem(value);
		comboBox.setSelectedItem(value);
	}
	if (!isSelected) {
		comboBox.setBackground(table.getBackground());
		comboBox.setForeground(table.getForeground());
	} else {
		comboBox.setBackground(table.getSelectionBackground());
		comboBox.setForeground(table.getSelectionForeground());
	}
	return comboBox;
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:46,代码来源:ComboBoxCellEditor.java


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