Example usage for javax.swing.table TableColumn setCellEditor

List of usage examples for javax.swing.table TableColumn setCellEditor

Introduction

In this page you can find the example usage for javax.swing.table TableColumn setCellEditor.

Prototype

@BeanProperty(description = "The editor to use for cell values.")
public void setCellEditor(TableCellEditor cellEditor) 

Source Link

Document

Sets the editor to used by when a cell in this column is edited.

Usage

From source file:org.piraso.ui.base.SaveMonitorInstanceDialog.java

private void initTable() {
    TableColumn selectionColumn = jtable.getColumnModel().getColumn(0);
    TableColumn boldOption = jtable.getColumnModel().getColumn(1);

    selectionColumn.setHeaderValue("");
    selectionColumn.setPreferredWidth(30);
    selectionColumn.setMaxWidth(30);/*from w w w . j ava 2s. c o  m*/
    selectionColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class));
    selectionColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class));

    boldOption.setHeaderValue("Request URL");
    boldOption.setPreferredWidth(200);

    jtable.setShowHorizontalLines(false);
    jtable.setAutoscrolls(true);
    jtable.setColumnSelectionAllowed(false);
    jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jtable.getTableHeader().setReorderingAllowed(false);
}

From source file:org.rimudb.editor.DescriptorEditor.java

/**
 * Build the panel//  w w  w.j ava2  s .  c  o m
 */
private JPanel createColumnTablePanel() {
    JPanel columnPanel = new JPanel();
    columnPanel.setLayout(new BoxLayout(columnPanel, BoxLayout.Y_AXIS));

    // Create the property table panel
    propertyModel = new PropertyTableModel();

    // Add a listener to set the changed state
    propertyModel.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            markChanged();

            if (e instanceof PropertyTableModelEvent) {
                PropertyTableModelEvent ptme = (PropertyTableModelEvent) e;

                // If the columnName column was changed then check it isn't
                // a PK
                if (ptme.getColumn() == 1) {

                    String beforeColumnName = (String) ptme.getBeforeValue();
                    String afterColumnName = (String) ptme.getAfterValue();

                    // Is the field entry in the list of primary keys?
                    for (int i = 0; i < pkListModel.getSize(); i++) {
                        String pkColumnName = (String) pkListModel.get(i);
                        // If it's found then remove it
                        if (beforeColumnName.equals(pkColumnName)) {
                            pkListModel.set(i, afterColumnName);
                            break;
                        }
                    }

                }

            }
        }
    });

    table = new ATable(getPropertyModel());
    table.setName("ColumnTable");
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int selectedRowCount = table.getSelectedRowCount();
            removeColumnBtn.setEnabled(selectedRowCount > 0);
            moveUpBtn.setEnabled(selectedRowCount > 0);
            moveDownBtn.setEnabled(selectedRowCount > 0);
        }
    });
    table.setTransferHandler(new TransferHandler() {

        public int getSourceActions(JComponent c) {
            return COPY;
        }

        protected Transferable createTransferable(JComponent c) {
            ATable columnTable = (ATable) c;
            int row = columnTable.getSelectedRow();
            String columnName = getPropertyModel().getRow(row).getColumnName();
            return new StringSelection(columnName);
        }
    });
    table.setDragEnabled(true);

    JScrollPane sp = new JScrollPane(table);
    sp.setMaximumSize(new Dimension(Short.MAX_VALUE, 325));
    sp.setPreferredSize(new Dimension(Short.MAX_VALUE, 325));
    sp.setMinimumSize(new Dimension(Short.MAX_VALUE, 325));

    JComboBox typeCB = new JComboBox(DatabaseTypes.getAllTypes());
    typeCB.setEditable(false);

    javax.swing.table.TableColumn typeColumn = table.getColumnModel().getColumn(2);
    typeColumn.setCellEditor(new DefaultCellEditor(typeCB));

    // Create the popup menu and set it on the table
    propertyPopup = new TablePopupMenu(this, table);
    table.addMouseListener(propertyPopup);
    sp.addMouseListener(propertyPopup);
    sp.setAlignmentX(LEFT_ALIGNMENT);

    columnPanel.add(sp);

    columnPanel.add(Box.createVerticalStrut(10));

    JLabel pkLabel = new JLabel("Primary Key Columns", SwingConstants.LEFT);
    pkLabel.setAlignmentX(LEFT_ALIGNMENT);
    columnPanel.add(pkLabel);

    pkListModel = new DefaultListModel();
    pkListModel.addListDataListener(new ListDataListener() {
        public void intervalRemoved(ListDataEvent e) {
            markChanged();
        }

        public void intervalAdded(ListDataEvent e) {
            markChanged();
        }

        public void contentsChanged(ListDataEvent e) {
            markChanged();
        }
    });

    pkList = new JList(pkListModel);
    pkList.setName("pkList");
    pkList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    pkList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int selectedRowCount = pkList.getSelectedIndex();
            removePkBtn.setEnabled(selectedRowCount > -1);
        }
    });
    pkList.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            if (dl.getIndex() == -1) {
                return false;
            }
            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            if (!info.isDrop()) {
                return false;
            }

            // Check for String flavor
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                displayDropLocation("List doesn't accept a drop of this type.");
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            DefaultListModel listModel = (DefaultListModel) pkList.getModel();
            int index = dl.getIndex();

            // Get the string that is being dropped.
            Transferable t = info.getTransferable();
            String data;
            try {
                data = (String) t.getTransferData(DataFlavor.stringFlavor);
            } catch (Exception e) {
                return false;
            }

            // If this is a copy action then check we don't already have that String
            if (info.getDropAction() == COPY && listModel.indexOf(data) > -1) {
                displayDropLocation("The column " + data + " is already a primary key");
                return false;
            }

            // Perform the actual import. 
            if (dl.isInsert()) {
                int oldIndex = listModel.indexOf(data);
                if (oldIndex < index) {
                    listModel.add(index, data);
                    listModel.remove(oldIndex);
                } else {
                    listModel.remove(oldIndex);
                    listModel.add(index, data);
                }
            } else {
                // Don't handle replacements
            }
            return true;
        }

        public int getSourceActions(JComponent c) {
            return MOVE;
        }

        protected Transferable createTransferable(JComponent c) {
            JList list = (JList) c;
            Object[] values = list.getSelectedValues();

            StringBuffer buff = new StringBuffer();

            for (int i = 0; i < values.length; i++) {
                Object val = values[i];
                buff.append(val == null ? "" : val.toString());
                if (i != values.length - 1) {
                    buff.append("\n");
                }
            }
            return new StringSelection(buff.toString());
        }
    });
    pkList.setDropMode(DropMode.INSERT);
    pkList.setDragEnabled(true);

    JScrollPane pkScrollPanel = new JScrollPane(pkList);
    pkScrollPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 100));
    pkScrollPanel.setAlignmentX(LEFT_ALIGNMENT);

    columnPanel.add(pkScrollPanel);

    return columnPanel;
}

From source file:org.smart.migrate.ui.MappingDialog.java

private void initFieldMappings() {
    if (StringUtils.isBlank((String) cbxSourceTables.getSelectedItem())
            || StringUtils.isBlank((String) cbxTargetTables.getSelectedItem())) {
        return;/*w w w.j  ava 2s  .c om*/
    }
    DefaultTableModel model = (DefaultTableModel) tblFieldMapping.getModel();
    model.setRowCount(0);
    TableColumn srcColumn = tblFieldMapping.getColumnModel().getColumn(0);
    TableColumn tgtColumn = tblFieldMapping.getColumnModel().getColumn(1);
    JComboBox srcComboBox = new JComboBox();
    srcComboBox.setMaximumRowCount(20);

    List<Field> srcFields = sourceMetaDao.getFieldsOfTable(sourceConnection,
            cbxSourceTables.getSelectedItem().toString());
    List<Field> tgtFields = targetMetaDao.getFieldsOfTable(targetConnection,
            cbxTargetTables.getSelectedItem().toString());

    srcComboBox.addItem("");
    for (Field field : srcFields) {
        srcComboBox.addItem(field.getName());
    }

    srcColumn.setCellEditor(new DefaultCellEditor(srcComboBox));

    int k = 0;
    for (Field tgtField : tgtFields) {
        k++;
        model.addRow(new Object[] { null, tgtField.getName(), false, null, null, k });
    }

    if (tableSetting != null && !CollectionUtils.isEmpty(tableSetting.getFieldSettings())
            && tableSetting.getSourceTable().equals(cbxSourceTables.getSelectedItem())
            && tableSetting.getTargetTable().equals(cbxTargetTables.getSelectedItem())) {

        for (int i = 0; i < tblFieldMapping.getRowCount(); i++) {
            String tgtField = (String) tblFieldMapping.getValueAt(i, 1);
            FieldSetting fieldSetting = tableSetting.getFieldSettingByTargetField(tgtField);
            if (fieldSetting != null) {
                tblFieldMapping.setValueAt(fieldSetting.getSourceField(), i, 0);
                tblFieldMapping.setValueAt(fieldSetting.isPrimaryKey(), i, 2);
                tblFieldMapping.setValueAt(fieldSetting.getDefaultValue(), i, 3);
                tblFieldMapping.setValueAt(fieldSetting.getDictText(), i, 4);
            }
        }
    }
}

From source file:org.tinymediamanager.ui.components.MediaIdTable.java

public MediaIdTable(EventList<MediaId> ids, ScraperType type) {
    this.idMap = null;
    this.editable = true;
    this.idList = ids;
    setModel(new DefaultEventTableModel<>(idList, new MediaIdTableFormat()));
    setTableHeader(null);// www  .  j av  a  2s . com
    putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    TableColumn column = getColumnModel().getColumn(0);

    Set<String> providerIds = new HashSet<>();
    for (MediaId id : ids) {
        providerIds.add(id.key);
    }
    for (MediaScraper scraper : MediaScraper.getMediaScrapers(type)) {
        providerIds.add(scraper.getId());
    }
    JComboBox<String> comboBox = new JComboBox<>(providerIds.toArray(new String[0]));

    column.setCellEditor(new DefaultCellEditor(comboBox));
}

From source file:org.yccheok.jstock.gui.JTableUtilities.java

/**
 * Sets the editor/renderer for Date objects to provided JTable, for the specified column.
 * @param table JTable to set up/*from w ww. j  av  a2  s. c  om*/
 * @param row Column to apply
 */
public static void setDateEditorAndRendererForRow(JTable table, int row) {
    final TableColumn column = table.getColumnModel().getColumn(row);
    // SwingX's. Pretty but buggy.
    //column.setCellEditor(new DatePickerCellEditor());
    column.setCellEditor(new DateFieldTableEditor());
    final DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT);
    column.setCellRenderer(new DateRendererDecoratorEx(column.getCellRenderer(), format));
}

From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java

public JXTablePerColumnFiltering(TableModel model) {
    super(model);
    this.model = (BeanTableModel<?>) model;

    // Create the 1-row filtering Table

    nColumns = model.getColumnCount();//w  ww.ja  v a  2s . c  om

    // DependencyEngine e = new DependencyEngine(new BasicEngineProvider());

    for (int row = 0; row < model.getRowCount(); row++) {
        for (int i = 0; i < nColumns; i++) {
            if (getColumnName(i).contains("userCell")) {
                // this is a column with cells that can contain formulas in addition to computed values
            } else {

            }
        }
    }

    filteringModel = new DefaultTableModel(1, nColumns);

    initializeFilterModel();

    filteringTable = new JXTableBetterFocus(filteringModel);
    filteringTable.setTableHeader(null);

    for (int i = 0; i < nColumns; i++) {
        TableColumn fColumn = filteringTable.getColumn(i);
        MultiRenderer multiRenderer = getMultiRenderer();

        fColumn.setCellRenderer(multiRenderer);
        fColumn.setCellEditor(multiRenderer);
        fColumn.setWidth(getColumn(i).getWidth());
    }

    this.setRowFilter(filter);

    JTableHeader header = this.getTableHeader();
    if (tips == null) {
        tips = new ColumnHeaderToolTips();
    }
    header.addMouseMotionListener(tips);
}

From source file:put.semantic.fcanew.ui.MainWindow.java

private void continueStart() {
    final List<Attribute> forced = getAttributes(2);
    if (forced.isEmpty()) {
        forced.addAll(getAttributes(1));
    }//ww w . jav  a2 s.co  m
    logger.trace("START");
    for (Attribute a : getUsedAttributes()) {
        logger.trace("ATTR: {}", a);
    }
    context = new PartialContext(new SimpleSetOfAttributes(getUsedAttributes()), kb);
    context.addProgressListener(progressListener);
    context.updateContext();
    contextTable.setRowSorter(new TableRowSorter<>());
    contextTable.setModel(new ContextDataModel(context));
    contextTable.setDefaultRenderer(Object.class, new PODCellRenderer(kb.getReasoner()));
    Enumeration<TableColumn> e = contextTable.getColumnModel().getColumns();
    JComboBox comboBox = new JComboBox(new Object[] { "+", "-", " " });
    while (e.hasMoreElements()) {
        TableColumn col = e.nextElement();
        col.setHeaderRenderer(new VerticalTableHeaderCellRenderer());
        col.setCellEditor(new DefaultCellEditor(comboBox));
        if (col.getModelIndex() >= 1) {
            col.setPreferredWidth(20);
        }
    }
    List<? extends FeatureCalculator> calculators = availableCalculatorsModel.getChecked();
    for (FeatureCalculator calc : calculators) {
        if (calc instanceof EndpointCalculator) {
            ((EndpointCalculator) calc).setMappings(mappingsPanel1.getMappings());
        }
    }
    Classifier classifier = (Classifier) classifierToUse.getSelectedItem();
    classifier.setRejectedWeight((Double) rejectedWeight.getValue());
    mlExpert = new MLExpert(classifier, (Integer) credibilityTreshold.getValue(), calculators,
            getIgnoreTreshold(), context, getAutoAcceptTreshold());
    mlExpert.addEventListener(new MLExpertEventListener() {

        @Override
        public void implicationAccepted(ImplicationDescription i, boolean autoDecision) {
            logger.trace("ACCEPT");
            setButtonsEnabled(false);
            ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.ACCEPT);
            registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.ACCEPT);
        }

        @Override
        public void implicationRejected(ImplicationDescription i, boolean autoDecision) {
            logger.trace("REJECT");
            setButtonsEnabled(false);
            ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.REJECT);
            registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.REJECT);
        }

        private TableModel getFeaturesTableModel(Map<String, Double> features) {
            DefaultTableModel model = new DefaultTableModel(new String[] { "feature", "value" }, 0);
            for (Map.Entry<String, Double> f : features.entrySet()) {
                model.addRow(new Object[] { f.getKey(), f.getValue() });
            }
            return model;
        }

        @Override
        public void ask(ImplicationDescription i, String justification) {
            logger.trace("ASK: {}", i.getImplication());
            highlightButton(i.getSuggestion());
            ((ContextDataModel) contextTable.getModel()).setCurrentImplication(i.getImplication());
            justificationText.setText(justification);
            implicationText.setText(String.format("<html>%s</html>", i.getImplication().toString()));
            {
                Map<String, String> desc = i.getImplication().describe(kb);
                String s = "<html><table border=\"1\">";
                s += "<tr><th>Attribute</th><th>Label</th></tr>";
                for (Map.Entry<String, String> e : desc.entrySet()) {
                    s += String.format("<tr><td>%s</td><td><pre>%s</pre></td></tr>", e.getKey(), e.getValue());
                }
                s += "</table></html>";
                implicationText.setToolTipText(s);
            }
            setButtonsEnabled(true);
            featuresTable.setModel(getFeaturesTableModel(i.getFeatures()));
        }
    });
    learningExamplesTable.setModel(classifier.getExamplesTableModel());
    fca = new FCA();
    fca.setContext(context);
    fca.setExpert(mlExpert);
    new SwingWorker() {
        @Override
        protected Object doInBackground() throws Exception {
            fca.reset(forced);
            fca.run();
            return null;
        }

        @Override
        protected void done() {
            try {
                get();
                logger.trace("FINISHED");
                if (script != null) {
                    String name = JOptionPane.showInputDialog(MainWindow.this,
                            "Jeeli chcesz otrzyma punkty z TSiSS, podaj swoje imi, nazwisko i nr indeksu",
                            "TSiSS", JOptionPane.QUESTION_MESSAGE);
                    if (name != null) {
                        logger.trace("NAME: {}", name);
                    }
                    script.submitLog(new File("fca.log"));
                }
                implicationText.setText("Bye-bye");
            } catch (InterruptedException | ExecutionException ex) {
                implicationText.setText(ex.getLocalizedMessage());
                ex.printStackTrace();
            }
        }
    }.execute();
}