コード例 #1
0
    @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;
    }
コード例 #2
0
 public MyValueEditor() {
   final ActionListener itemChoosen =
       new ActionListener() {
         @Override
         public void actionPerformed(@NotNull ActionEvent e) {
           if (myCurrentNode != null) {
             myCurrentNode.setValue(getCellEditorValue());
             somethingChanged();
           }
         }
       };
   myBooleanEditor.addActionListener(itemChoosen);
   myOptionsEditor.addActionListener(itemChoosen);
   myBooleanEditor.putClientProperty("JComponent.sizeVariant", "small");
   myOptionsEditor.putClientProperty("JComponent.sizeVariant", "small");
 }