@NotNull @Override public Component getTableCellRendererComponent( @NotNull JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { myTable = table; myRow = row; myColumn = column; boolean isEnabled = true; final DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((TreeTable) table).getTree().getPathForRow(row).getLastPathComponent(); Option key = null; if (node instanceof MyTreeNode) { isEnabled = ((MyTreeNode) node).isEnabled(); key = ((MyTreeNode) node).getKey(); } if (!table.isEnabled()) { isEnabled = false; } Color background = table.getBackground(); if (value instanceof Boolean) { myCheckBox.setSelected(((Boolean) value).booleanValue()); myCheckBox.setBackground(background); myCheckBox.setEnabled(isEnabled); return myCheckBox; } else if (value instanceof String) { /* myComboBox.removeAllItems(); myComboBox.addItem(value); */ myComboBox.setText((String) value); myComboBox.setBackground(background); myComboBox.setEnabled(isEnabled); return myComboBox; } else if (value instanceof Integer) { if (key instanceof IntOption && ((IntOption) key).isDefaultValue(value)) { myIntLabel.setText(((IntOption) key).getDefaultValueText()); } else { myIntLabel.setText(value.toString()); } return myIntLabel; } myCheckBox.putClientProperty("JComponent.sizeVariant", "small"); myComboBox.putClientProperty("JComponent.sizeVariant", "small"); myEmptyLabel.setBackground(background); return myEmptyLabel; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean selected, boolean focused, int row, int column) { setEnabled(table == null || table.isEnabled()); if (column == 0 || column == 1) { setHorizontalAlignment(SwingConstants.CENTER); setForeground(null); setBackground(null); } else { setHorizontalAlignment(SwingConstants.RIGHT); for (int i = 0; i < highlightIndex.size(); i++) { if (row == ((Integer) highlightIndex.elementAt(i)).intValue()) { setForeground(Color.blue); break; } else setForeground(null); } if (row == flashIndex) { setBackground(Color.orange); } else setBackground(null); } super.getTableCellRendererComponent(table, value, selected, focused, row, column); return this; }
private boolean shouldIgnore(MouseEvent e) { return e.isConsumed() || (!(SwingUtilities.isLeftMouseButton(e) && table.isEnabled())); }