Example usage for javax.swing DefaultCellEditor DefaultCellEditor

List of usage examples for javax.swing DefaultCellEditor DefaultCellEditor

Introduction

In this page you can find the example usage for javax.swing DefaultCellEditor DefaultCellEditor.

Prototype

public DefaultCellEditor(final JComboBox<?> comboBox) 

Source Link

Document

Constructs a DefaultCellEditor object that uses a combo box.

Usage

From source file:zet.gui.assignmentEditor.JAssignmentPanel.java

/**
 * Adds all components to the panel./*from   w  w  w  .j  a  va 2 s.c o m*/
 */
private void addComponents() {
    setLayout(new BorderLayout());
    initDistributions();

    // Create the main table
    tablemodel = new AssignmentTableModel();
    tablemodel.addTableModelListener(e -> {
        drawCharts();
    });
    distributionTable = new JTable(tablemodel);
    distributionTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    distributionTable.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
        drawCharts();
    });

    distributions = new JComboBox<>();
    distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.NormalDistribution"));
    distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.UniformDistribution"));
    distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.ExponentialDistribution"));
    distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.ErlangDistribution"));
    distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.HyperExponentialDistribution"));
    distributionTable.getColumnModel().getColumn(COL_DISTRIBUTION)
            .setCellEditor(new DefaultCellEditor(distributions));
    distributionTable.getColumnModel().getColumn(COL_PARAM1).setCellEditor(new SelectingCellEditor());
    distributionTable.getColumnModel().getColumn(COL_PARAM2).setCellEditor(new SelectingCellEditor());
    distributionTable.getColumnModel().getColumn(COL_PARAM3).setCellEditor(new SelectingCellEditor());
    distributionTable.getColumnModel().getColumn(COL_PARAM4).setCellEditor(new SelectingCellEditor());
    distributionTable.getColumnModel().getColumn(COL_PARAM3).setCellRenderer(new InactiveRenderer());
    distributionTable.getColumnModel().getColumn(COL_PARAM4).setCellRenderer(new InactiveRenderer());

    add(getRightPanel(), BorderLayout.CENTER);
    final JPanel leftPanel = getLeftPanel();
    leftPanel.setMaximumSize(new Dimension(200, 0));
    add(leftPanel, BorderLayout.WEST);
    assignmentSelector.displayAssignments(myProject.getProject());
}

From source file:edu.ku.brc.af.ui.weblink.WebLinkEditorDlg.java

@Override
public void createUI() {
    super.createUI();

    nameTF = UIHelper.createTextField();
    baseUrlTF = UIHelper.createTextField(25);
    descTA = UIHelper.createTextArea();//from  w ww .java 2s .c  om

    descTA.setLineWrap(true);
    descTA.setWrapStyleWord(true);

    txtFGColor = nameTF.getForeground();
    txtBGColor = nameTF.getBackground();

    if (isEdit) {
        ViewFactory.changeTextFieldUIForDisplay(nameTF, true);
    }

    descTA.setRows(5);

    model = new WebLinkArgsTableModel();
    table = new JTable(model);
    table.setDefaultRenderer(String.class, new BiColorTableCellRenderer(true));

    CellConstraints cc = new CellConstraints();
    PanelBuilder rightPB = new PanelBuilder(new FormLayout("p,2px,f:p:g", //$NON-NLS-1$
            "p,2px,p, 4px,p,2px,200px" + (tableInfo != null ? ",2px,200px" : ""))); //$NON-NLS-1$

    rightPB.add(createI18NFormLabel("WebLinkArgDlg.NAME"), cc.xy(1, 1)); //$NON-NLS-1$ //$NON-NLS-2$
    rightPB.add(nameTF, cc.xy(3, 1));

    rightPB.add(createI18NFormLabel("WebLinkArgDlg.URL"), cc.xy(1, 3)); //$NON-NLS-1$ //$NON-NLS-2$
    rightPB.add(baseUrlTF, cc.xy(3, 3));

    rightPB.add(createI18NFormLabel("WebLinkArgDlg.DESC"), cc.xy(1, 5)); //$NON-NLS-1$ //$NON-NLS-2$
    rightPB.add(UIHelper.createScrollPane(descTA), cc.xy(3, 5));

    rightPB.add(createI18NFormLabel("WebLinkArgDlg.FIELDS"), cc.xy(1, 7)); //$NON-NLS-1$ //$NON-NLS-2$
    rightPB.add(UIHelper.createScrollPane(table), cc.xy(3, 7));

    if (tableInfo != null) {
        rightPB.add(UIHelper.createScrollPane(availableFields), cc.xy(3, 9));
    }

    rightPB.setDefaultDialogBorder();

    TableColumn promptCol = table.getColumnModel().getColumn(2);
    promptCol.setCellEditor(new DefaultCellEditor(new JCheckBox()));
    //promptCol.setCellRenderer(cellRenderer)
    UIHelper.makeTableHeadersCentered(table, false);

    contentPanel = rightPB.getPanel();
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    pack();

    setDataIntoUI();

    DocumentListener docLis = new DocumentListener() {
        protected void changed() {
            hasChanged = true;
            parseForFields();
            enableUI();
        }

        public void changedUpdate(DocumentEvent e) {
            changed();
        }

        public void insertUpdate(DocumentEvent e) {
            changed();
        }

        public void removeUpdate(DocumentEvent e) {
            changed();
        }
    };

    nameTF.getDocument().addDocumentListener(docLis);
    baseUrlTF.getDocument().addDocumentListener(docLis);

    adjustAvailableJList();

    enableUI();

    pack();
}

From source file:net.sourceforge.happybank.main.BankMain.java

private void initComponents() {
    frame = new javax.swing.JFrame();
    menuBar = new javax.swing.JMenuBar();
    menuFile = new javax.swing.JMenu();
    menuItemExit = new javax.swing.JMenuItem();
    menuActions = new javax.swing.JMenu();
    menuItemView = new javax.swing.JMenuItem();
    separator2 = new javax.swing.JSeparator();
    menuHelp = new javax.swing.JMenu();
    separator4 = new javax.swing.JSeparator();
    menuItemAbout = new javax.swing.JMenuItem();
    accountEntries = new javax.swing.JTable();
    accountModel = new AccountTableModel();

    /*/*ww  w  .  ja va  2 s . c om*/
     * File menu
     */
    menuFile.setMnemonic('F');
    menuFile.setText("File");
    // - Exit option
    menuItemExit.setMnemonic('X');
    menuItemExit.setText("Exit");
    menuItemExit.setActionCommand("Exit");
    menuItemExit.addActionListener(new ActionHandler());
    menuFile.add(menuItemExit);
    menuBar.add(menuFile);

    // Actions menu
    menuActions.setMnemonic('A');
    menuActions.setText("Actions");
    // - View option
    menuItemView.setMnemonic('V');
    menuItemView
            .setAccelerator(KeyStroke.getKeyStroke('V', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menuItemView.setText("View");
    menuItemView.setActionCommand("View");
    menuItemView.addActionListener(new ActionHandler());
    menuActions.add(menuItemView);
    menuActions.add(separator2);

    // Help menu
    menuHelp.setMnemonic('H');
    menuHelp.setText("Help");
    // - About option
    menuHelp.add(separator4);
    menuItemAbout.setMnemonic('A');
    menuItemAbout.setText("About");
    menuItemAbout.setActionCommand("About");
    menuItemAbout.addActionListener(new ActionHandler());
    menuHelp.add(menuItemAbout);
    menuBar.add(menuHelp);

    /*
     * configure the TabListCellRenderer
     */
    accountEntries.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    accountEntries.setAutoCreateColumnsFromModel(false);
    accountEntries.setModel(accountModel);
    accountEntries.getTableHeader().setReorderingAllowed(false);
    accountEntries.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    accountEntries.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            // capture single click
            if (evt.getClickCount() == 1 && SwingUtilities.isLeftMouseButton(evt)) {
                // ignore
            }
            // capture double click
            if (evt.getClickCount() == 2) {
                // edit the account
                int row = accountEntries.rowAtPoint(evt.getPoint());
                accountEntries.setRowSelectionInterval(row, row);
                onViewAccount();
            }
        } // mouseClicked
    }); // MouseAdapter

    // set the column widths and alignment
    for (int k = 0; k < AccountTableModel.COLUMNS.length; k++) {
        TableCellEditor zipper = new DefaultCellEditor(new JTextField());
        DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer();
        textRenderer.setHorizontalAlignment(AccountTableModel.COLUMNS[k].cAlignment);
        TableColumn column = new TableColumn(k, AccountTableModel.COLUMNS[k].cWidth, textRenderer, zipper);
        accountEntries.addColumn(column);
    }

    // set the table header
    JTableHeader header = accountEntries.getTableHeader();
    header.setUpdateTableInRealTime(false);

    /*
     * create the selection area
     */
    accountPanel = new JPanel();
    accountPanel.setLayout(new BorderLayout());
    scrollPane = new JScrollPane(accountEntries);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new java.awt.Dimension(750, 300));
    accountPanel.add(scrollPane);
    frame.getContentPane().add(accountPanel, java.awt.BorderLayout.CENTER);

    /*
     * layout the frame
     */
    frame.setJMenuBar(menuBar);
    frame.setTitle(APP_NAME);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(screenSize.width / 2 - 300, screenSize.height / 2 - 200);
    // add a listener for the close event
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            onExit();
        }
    });

    loadAccounts();
}

From source file:edu.harvard.mcz.imagecapture.DeterminationFrame.java

private void setTableColumnEditors() {
    JComboBox<String> comboBoxNatureOfId = new JComboBox<String>(NatureOfId.getNatureOfIdValues());
    jTableDeterminations.getColumnModel().getColumn(DeterminationTableModel.ROW_NATUREOFID)
            .setCellEditor(new DefaultCellEditor(comboBoxNatureOfId));

    JComboBox<String> comboBoxTypeStatus = new JComboBox<String>(TypeStatus.getTypeStatusValues());
    jTableDeterminations.getColumnModel().getColumn(DeterminationTableModel.ROW_TYPESTATUS)
            .setCellEditor(new DefaultCellEditor(comboBoxTypeStatus));

    JTextField jTextFieldDateIdentified = new JTextField();
    jTextFieldDateIdentified.setInputVerifier(MetadataRetriever.getInputVerifier(Determination.class,
            "DateIdentified", jTextFieldDateIdentified));
    jTableDeterminations.getColumnModel().getColumn(DeterminationTableModel.ROW_DATEIDENTIFIED)
            .setCellEditor(new ValidatingTableCellEditor(jTextFieldDateIdentified));

}

From source file:logdruid.ui.table.StatRecordingEditorTable.java

public void setUpTypeColumn(JTable theTable, TableColumn TypeColumn) {
    // Set up the editor for the Type cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("word");
    comboBox.addItem("string");
    comboBox.addItem("long");
    comboBox.addItem("double");
    comboBox.addItem("date");
    comboBox.addItem("percent");
    TypeColumn.setCellEditor(new DefaultCellEditor(comboBox));

    // Set up tool tips for the Type cells.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    TypeColumn.setCellRenderer(renderer);
}

From source file:logdruid.ui.table.EventRecordingEditorTable.java

public void setUpProcessingColumn(JTable theTable, TableColumn typeColumn) {
    JComboBox functionComboBox = new JComboBox();
    functionComboBox.addItem("capture");
    functionComboBox.addItem("duration");
    functionComboBox.addItem("occurrences");
    functionComboBox.addItem("sum");
    typeColumn.setCellEditor(new DefaultCellEditor(functionComboBox));
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    typeColumn.setCellRenderer(renderer);
}

From source file:hermes.browser.dialog.HermesAdminFactoryConfigPanel.java

public void updateCellEditor() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (propertyTable.getColumnModel().getColumnCount() > 0) {
        final TableColumn propertyNameColumn = propertyTable.getColumnModel().getColumn(0);

        propertySelectionComboBox = new JComboBox();
        boolean isJNDI = false;

        try {/* www  .j  a  v  a 2s  . com*/
            Map properties = BeanUtils.describe(bean);

            log.debug("bean= " + properties);

            for (Iterator iter = propertyTableModel.getValidProperties().iterator(); iter.hasNext();) {
                String name = (String) iter.next();

                propertySelectionComboBox.addItem(name);
            }
        } catch (InvocationTargetException e) {
            cat.error(e.getTargetException().getMessage(), e.getTargetException());
        }

        propertyNameColumn.setCellEditor(new DefaultCellEditor(propertySelectionComboBox));
    }
}

From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java

public void setColumnType(JTable table) {
    table.setShowVerticalLines(false);//from ww w . j  ava 2s  .  c o  m
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(false);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setRowHeight(30);

    JTableHeader header = table.getTableHeader();
    header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30));
    header.setFont(new Font("Arial", Font.BOLD, 12));
    header.setReorderingAllowed(false);

    TableColumnModel cm = table.getColumnModel();
    TableColumn col = null;

    analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET),
            "Analyze Target");
    col = cm.getColumn(COL_ANALYZE_TARGET);
    col.setHeaderRenderer(analyzeHeader);

    JCheckBox chkbox = new JCheckBox();
    chkbox.setBackground(Color.white);
    chkbox.setHorizontalAlignment(JLabel.CENTER);
    col.setCellRenderer(new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 1L;

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel();

            String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME);
            OSIProjectInfo item = model.getProjectInfo(sPrjName);

            JCheckBox chkbox = new JCheckBox();
            chkbox.setSelected(((Boolean) value).booleanValue());
            if (item != null) {
                chkbox.setEnabled(item.isLocationValid());
            }
            chkbox.setHorizontalAlignment(JLabel.CENTER);
            chkbox.setBackground(Color.white);

            return (Component) chkbox;
        }
    });
    col.setCellEditor(new DefaultCellEditor(chkbox));

    col = cm.getColumn(COL_ANALYZE_STATUS);
    col.setCellRenderer(new StatusIconCellRenderer());

    col = cm.getColumn(COL_SOURCE_LOCATION);
    col.setCellRenderer(new FileBrowseCellRenderer());
    col.setCellEditor(new FileBrowseCellEditor());
}

From source file:logdruid.ui.table.EventRecordingEditorTable.java

public void setUpTypeColumn(JTable theTable, TableColumn typeColumn) {
    // Set up the editor for the type cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("word");
    comboBox.addItem("string");
    comboBox.addItem("long");
    comboBox.addItem("double");
    comboBox.addItem("date");
    comboBox.addItem("percent");

    typeColumn.setCellEditor(new DefaultCellEditor(comboBox));

    // Set up tool tips for the type cells.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    typeColumn.setCellRenderer(renderer);
}

From source file:dbseer.gui.user.DBSeerDataSet.java

public DBSeerDataSet(boolean isLive) {
    live = new Boolean(isLive);
    Boolean[] trueFalse = { Boolean.TRUE, Boolean.FALSE };
    JComboBox trueFalseBox = new JComboBox(trueFalse);
    final DefaultCellEditor dce = new DefaultCellEditor(trueFalseBox);

    uniqueVariableName = "dataset_" + UUID.randomUUID().toString().replace('-', '_');
    uniqueModelVariableName = "mv_" + UUID.randomUUID().toString().replace('-', '_');
    if (isLive) {
        name = "Live Data";
    }/*w w  w  .j a  v  a2s.c o  m*/
    tableModel = new DBSeerDataSetTableModel(null, new String[] { "Name", "Value" }, !isLive);
    tableModel.addTableModelListener(this);
    table = new JTable(tableModel) {
        @Override
        public TableCellEditor getCellEditor(int row, int col) {
            if ((row == DBSeerDataSet.TYPE_USE_ENTIRE_DATASET
                    || row > TYPE_NUM_TRANSACTION_TYPE + numTransactionTypes) && col == 1)
                return dce;
            return super.getCellEditor(row, col);
        }
    };
    DefaultTableCellRenderer customRenderder = new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable jTable, Object o, boolean b, boolean b2, int row,
                int col) {
            Component cell = super.getTableCellRendererComponent(jTable, o, b, b2, row, col);
            if (row == DBSeerDataSet.TYPE_START_INDEX || row == DBSeerDataSet.TYPE_END_INDEX) {
                if (((Boolean) table.getValueAt(DBSeerDataSet.TYPE_USE_ENTIRE_DATASET, 1))
                        .booleanValue() == true) {
                    cell.setForeground(Color.LIGHT_GRAY);
                } else {
                    cell.setForeground(Color.BLACK);
                }
            }
            //            else if (row == DBSeerDataSet.TYPE_AVERAGE_LATENCY ||
            //                  row == DBSeerDataSet.TYPE_HEADER ||
            //                  row == DBSeerDataSet.TYPE_MONITORING_DATA ||
            //                  row == DBSeerDataSet.TYPE_PERCENTILE_LATENCY ||
            //                  row == DBSeerDataSet.TYPE_TRANSACTION_COUNT ||
            //                  row == DBSeerDataSet.TYPE_NUM_TRANSACTION_TYPE ||
            //                  row == DBSeerDataSet.TYPE_STATEMENT_FILE ||
            //                  row == DBSeerDataSet.TYPE_QUERY_FILE ||
            //                  row == DBSeerDataSet.TYPE_TRANSACTION_FILE)
            else if (row == DBSeerDataSet.TYPE_NUM_TRANSACTION_TYPE) {
                cell.setForeground(Color.LIGHT_GRAY);
            } else {
                cell.setForeground(Color.BLACK);
            }
            return cell;
        }
    };
    table.getColumnModel().getColumn(0).setCellRenderer(customRenderder);
    table.getColumnModel().getColumn(1).setCellRenderer(customRenderder);

    table.setFillsViewportHeight(true);
    table.getColumnModel().getColumn(0).setMaxWidth(400);
    table.getColumnModel().getColumn(0).setPreferredWidth(300);
    table.getColumnModel().getColumn(1).setPreferredWidth(600);
    table.setRowHeight(20);

    this.useEntireDataSet = true;
    for (String header : tableHeaders) {
        if (header.equalsIgnoreCase("Use Entire DataSet"))
            tableModel.addRow(new Object[] { header, Boolean.TRUE });
        else
            tableModel.addRow(new Object[] { header, "" });
    }

    this.updateLiveDataSet();

    for (int i = 0; i < numTransactionTypes; ++i) {
        tableModel.addRow(new Object[] { "Name of Transaction Type " + (i + 1), "Type " + (i + 1) });
        DBSeerTransactionType type = new DBSeerTransactionType("Type " + (i + 1), true);
        transactionTypes.add(type);
    }

    for (int i = 0; i < transactionTypes.size(); ++i) {
        DBSeerTransactionType txType = transactionTypes.get(i);
        if (txType.isEnabled()) {
            tableModel.addRow(new Object[] { "Use Transaction Type " + (i + 1), Boolean.TRUE });
        } else {
            tableModel.addRow(new Object[] { "Use Transaction Type " + (i + 1), Boolean.FALSE });
        }
    }

    this.updateTable();
    dataSetLoaded = false;

    tableModel.setUseEntireDataSet(this.useEntireDataSet.booleanValue());
}