Пример #1
0
        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
          MyTableModel model = (MyTableModel) getModel();
          if (column == 0) {
            // JXTable default renderer doesn't align right
            DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
            renderer.setToolTipText(model.getToolTipText(row));
            renderer.setHorizontalAlignment(JLabel.RIGHT);
            if (model.isExpert(row, column)) {
              renderer.setForeground(Color.GRAY);
            }
            return renderer;
          }

          // code repetition with getCellEditor because of TableCell{Renderer, Editor}
          // non-inheritance
          Class<?> klass = model.getClassAt(row, column);
          PropertyEditorTableAdapter javaBeansRenderer = PropertyEditorTableAdapter.forClass(klass);
          if (javaBeansRenderer != null) {
            return javaBeansRenderer;
          }
          return getDefaultRenderer(klass);
        }
Пример #2
0
        @Override
        public TableCellEditor getCellEditor(int row, int column) {
          MyTableModel model = (MyTableModel) getModel();
          if (column == 0) {
            return null;
          }

          // code repetition with getCellRenderer because of TableCell{Renderer, Editor}
          // non-inheritance
          Class<?> klass = model.getClassAt(row, column);
          PropertyEditorTableAdapter javaBeansEditor = PropertyEditorTableAdapter.forClass(klass);
          if (javaBeansEditor != null) {
            return javaBeansEditor;
          }
          TableCellEditor defaultEditor = getDefaultEditor(klass);
          if (defaultEditor == null) {
            log.warning("No TableCellEditor for " + klass.getName());
          }
          if (defaultEditor instanceof DefaultCellEditor) {
            // default double-click is bad user interaction
            ((DefaultCellEditor) defaultEditor).setClickCountToStart(0);
          }
          return defaultEditor;
        }