@NotNull @Override public Component getTreeCellRendererComponent( @NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof MyTreeNode) { MyTreeNode node = (MyTreeNode) value; myLabel.setText(getRenamedTitle(node.getKey().field.getName(), node.getText())); myLabel.setFont( myLabel .getFont() .deriveFont(node.getKey().groupName == null ? Font.BOLD : Font.PLAIN)); myLabel.setEnabled(node.isEnabled()); } else { myLabel.setText(getRenamedTitle(value.toString(), value.toString())); myLabel.setFont(myLabel.getFont().deriveFont(Font.BOLD)); myLabel.setEnabled(true); } Color foreground = selected ? UIUtil.getTableSelectionForeground() : UIUtil.getTableForeground(); myLabel.setForeground(foreground); return myLabel; }
@Override public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { final DefaultMutableTreeNode defaultNode = (DefaultMutableTreeNode) ((TreeTable) table).getTree().getPathForRow(row).getLastPathComponent(); myCurrentEditor = null; myCurrentNode = null; if (defaultNode instanceof MyTreeNode) { MyTreeNode node = (MyTreeNode) defaultNode; myCurrentNode = node; if (node.getKey() instanceof BooleanOption) { myCurrentEditor = myBooleanEditor; myBooleanEditor.setSelected(node.getValue() == Boolean.TRUE); myBooleanEditor.setEnabled(node.isEnabled()); } else if (node.getKey() instanceof IntOption) { IntOption intOption = (IntOption) node.getKey(); myCurrentEditor = myIntOptionsEditor; myIntOptionsEditor.setText( intOption.isDefaultValue(node.getValue()) ? "" : node.getValue().toString()); myIntOptionsEditor.setMinValue(intOption.getMinValue()); myIntOptionsEditor.setMaxValue(intOption.getMaxValue()); myIntOptionsEditor.setDefaultValue(intOption.getDefaultValue()); } else { myCurrentEditor = myOptionsEditor; myOptionsEditor.setCell(table, row, column); myOptionsEditor.setText(String.valueOf(node.getValue())); myOptionsEditor.setOptions(((SelectionOption) node.getKey()).options); myOptionsEditor.setDefaultValue(node.getValue()); } } if (myCurrentEditor != null) { myCurrentEditor.setBackground(table.getBackground()); } return myCurrentEditor; }