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:au.com.jwatmuff.eventmanager.gui.admin.WithdrawPlayerDialog.java

/** Creates new form WithdrawPlayerDialog */
public WithdrawPlayerDialog(java.awt.Frame parent, boolean modal, Database database,
        TransactionNotifier notifier) {// ww w .  ja  v a2s .  c o m
    super(parent, modal);
    initComponents();
    setLocationRelativeTo(null);

    this.database = database;
    this.notifier = notifier;

    divisionTableModel = new DivisionTableModel();
    divisionTableModel.updateFromDatabase();
    divisionTable.setModel(divisionTableModel);
    divisionTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    divisionTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            playerTableModel.updateFromDatabase();
        }
    });
    notifier.addListener(divisionTableModel, Pool.class);

    playerTableModel = new PlayerTableModel();
    playerTable.setModel(playerTableModel);
    playerTable.setSelectionModel(new NullSelectionModel()); // disable selection
    // set up cell editor for status column
    // see PlayerTableModel.setValueAt() for how edits to cells are handled
    playerTable.getColumnModel().getColumn(1)
            .setCellEditor(new DefaultCellEditor(new JComboBox<Status>(statuses)));
    playerTable.getColumnModel().getColumn(1).setCellRenderer(new ComboBoxCellRenderer(Status.values()));
    // sort by name
    playerTable.getRowSorter().setSortKeys(Arrays.asList(new RowSorter.SortKey(0, SortOrder.ASCENDING)));
    notifier.addListener(playerTableModel, PlayerPool.class);
}

From source file:OAT.ui.util.UiUtil.java

public static void addComboCell(TableColumn column, Object[] items) {
    column.setCellEditor(new DefaultCellEditor(new JComboBox(items)));
}

From source file:TableRenderDemo.java

public void setUpSportColumn(JTable table, TableColumn sportColumn) {
    // Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Snowboarding");
    comboBox.addItem("Rowing");
    comboBox.addItem("Knitting");
    comboBox.addItem("Speed reading");
    comboBox.addItem("Pool");
    comboBox.addItem("None of the above");
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));

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

From source file:hr.fer.zemris.vhdllab.platform.ui.wizard.support.PortWizardPage.java

@SuppressWarnings("unchecked")
@Override//from   w w  w .ja  va  2  s.c o m
protected JComponent createControl() {
    model = new BeanTableModel(Port.class, new ArrayList<Port>(), getMessageSource()) {
        private static final long serialVersionUID = 1L;

        @Override
        protected String[] createColumnPropertyNames() {
            return new String[] { "name", "direction", "from", "to" };
        }

        @Override
        protected Class[] createColumnClasses() {
            return new Class[] { String.class, PortDirection.class, Integer.class, Integer.class };
        }

    };
    reporter = new PortValidationReporter(model, this, minimumPortCount, maximumPortCount);
    table = new JTable(model);
    table.setCellSelectionEnabled(true);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            removeAction.setEnabled(!table.getSelectionModel().isSelectionEmpty());
        }
    });

    final JComboBox inComboBox = new JComboBox(new EnumComboBoxModel(PortDirection.class));
    JTextField portName = new JTextField();

    new ComboBoxAutoCompletion(inComboBox);

    table.getColumnModel().getColumn(0).setPreferredWidth(7);
    table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(portName));
    table.getColumnModel().getColumn(1).setPreferredWidth(120);
    table.getColumnModel().getColumn(2).setCellEditor(new ComboBoxCellEditor(inComboBox));
    table.getColumnModel().getColumn(3).setCellEditor(new NumberEditorExt());
    table.getColumnModel().getColumn(4).setCellEditor(new NumberEditorExt());
    table.setPreferredScrollableViewportSize(new Dimension(300, 200));

    table.addKeyListener(new EditComboBoxKeyHandler());

    JScrollPane scrollPane = new JScrollPane(table);
    JPanel control = new JPanel(new BorderLayout());
    control.add(createButtons(), BorderLayout.NORTH);
    control.add(scrollPane, BorderLayout.CENTER);
    return control;
}

From source file:components.TableRenderDemo.java

public void setUpSportColumn(JTable table, TableColumn sportColumn) {
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Snowboarding");
    comboBox.addItem("Rowing");
    comboBox.addItem("Knitting");
    comboBox.addItem("Speed reading");
    comboBox.addItem("Pool");
    comboBox.addItem("None of the above");
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));

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

From source file:com.emr.schemas.TableRelationsForm.java

/**
 * Constructor/*from   ww w .  j a va 2s  .c  o  m*/
 * @param tables {@link List} List of source tables
 */
public TableRelationsForm(List tables, SchemerMapper parent) {
    fileManager = null;
    dbManager = null;
    emrConn = null;
    this.parent = parent;
    this.tables = tables; //source tables

    //Create KenyaEMR DB connection
    fileManager = new FileManager();
    String[] settings = fileManager.getConnectionSettings("emr_database.properties", "emr");
    if (settings == null) {
        //Connection settings not found
        JOptionPane.showMessageDialog(null,
                "Database Settings not found. Please set the connection settings for the database first.",
                "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
        //Open KenyaEMRConnectionForm form
    } else {
        if (settings.length < 1) {
            JOptionPane.showMessageDialog(null,
                    "Database Settings not found. Please set the connection settings for the database first.",
                    "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
            //Open KenyaEMRConnectionForm form
        } else {
            //Connection settings are ok
            //We establish a connection
            dbManager = new DatabaseManager(settings[0], settings[1], settings[3], settings[4], settings[5]);
            emrConn = dbManager.getConnection();
            if (emrConn == null) {
                JOptionPane.showMessageDialog(null, "Test Connection Failed", "Connection Test",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    //get all columns and add them to the columns list
    for (Object table : tables) {
        String tablename = (String) table;
        populateTableColumnsToList(tablename);
    }

    model = new DefaultTableModel(
            new Object[] { "Primary Table", "Column", "Reference Table", "Foreign Column" }, 10);

    initComponents();
    this.setClosable(true);
    foreignTables = tables;
    combo1 = new JComboBox();//Combobox for the primary tables
    combo2 = new JComboBox();
    combo3 = new JComboBox();
    combo4 = new JComboBox();
    combo1.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate primary table columns
                primaryColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo2_model = new DefaultComboBoxModel(
                        primaryColumns.toArray(new String[primaryColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo2_model);
                relationsTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox));

            }
        }
    });

    combo3.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate foreign table columns
                foreignColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo3_model = new DefaultComboBoxModel(
                        foreignColumns.toArray(new String[foreignColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo3_model);
                relationsTable.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBox));
            }
        }
    });
    ComboBoxTableCellEditor primaryTableEditor = new ComboBoxTableCellEditor(tables, combo1);
    ComboBoxTableCellEditor primaryTableColumns = new ComboBoxTableCellEditor(primaryColumns, combo2);

    ComboBoxTableCellEditor foreignTableEditor = new ComboBoxTableCellEditor(foreignTables, combo3);//TODO: remove selected primary table from list

    ComboBoxTableCellEditor foreignTableColumns = new ComboBoxTableCellEditor(foreignColumns, combo4);
    relationsTable.getColumnModel().getColumn(0).setCellEditor(primaryTableEditor);
    relationsTable.getColumnModel().getColumn(1).setCellEditor(primaryTableColumns);
    relationsTable.getColumnModel().getColumn(2).setCellEditor(foreignTableEditor);
    relationsTable.getColumnModel().getColumn(3).setCellEditor(foreignTableColumns);

    columnsList.setCellRenderer(new CheckboxListCellRenderer());
    SourceTablesListener listSelectionListener = new SourceTablesListener(new JTextArea(), selected_columns);
    columnsList.addListSelectionListener(listSelectionListener);
    columnsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    columnsList.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (isSelectedIndex(index0))
                super.removeSelectionInterval(index0, index1);
            else
                super.addSelectionInterval(index0, index1);
        }
    });
}

From source file:gov.nij.er.ui.EntityResolutionDemo.java

private EntityResolutionDemo(boolean test) {

    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent arg0) {
            exit();//  w ww.  j  a v a 2s  . c  o  m
        }

    });

    setTitle("Entity Resolution Demo");

    setJMenuBar(buildMenuBar());

    createUIWidgets();

    layoutUI();
    setupWidgetModels();
    setupWidgetListeners();

    parametersTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(algorithmComboBox));

    if (test) {
        loadTestRecords();
    }

    updateUIForParameterChange();

    setSize(800, 600);
    setVisible(true);

}

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

public DBSeerDataSet() {
    live = new Boolean(false);
    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('-', '_');
    name = "Unnamed dataset";
    tableModel = new DBSeerDataSetTableModel(null, new String[] { "Name", "Value" }, true);
    tableModel.addTableModelListener(this);
    table = new JTable(tableModel) {
        @Override/*  w w  w  .j  a va2  s . c o m*/
        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_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, "" });
    }

    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;
    isCurrent = false;

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

From source file:net.sf.profiler4j.console.ProjectDialog.java

/**
 * This method initializes rulesTable/*from   www .  ja  v a 2s .  c  o  m*/
 * 
 * @return javax.swing.JTable
 */
private JTable getRulesTable() {
    if (rulesTable == null) {
        rulesTable = new JTable();
        rulesTable.setModel(ruleTableModel);
        rulesTable.setRowMargin(4);
        rulesTable.setRowHeight(24);
        rulesTable.setFont(new Font("Monospaced", Font.PLAIN, 14));
        TableColumn c;

        c = rulesTable.getColumnModel().getColumn(0);
        c.setMinWidth(300);

        c = rulesTable.getColumnModel().getColumn(1);
        c.setMinWidth(80);
        c.setMaxWidth(80);

        JComboBox editorCb = new JComboBox();
        for (Rule.Action a : Rule.Action.values()) {
            editorCb.addItem(a);
        }
        c.setCellEditor(new DefaultCellEditor(editorCb));
        c.setCellRenderer(new DefaultTableCellRenderer() {
            Font font = new Font("Monospaced", Font.BOLD, 13);

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                Rule.Action r = (Rule.Action) value;
                setHorizontalAlignment(CENTER);
                setFont(font);
                if (r == Rule.Action.ACCEPT) {
                    setBackground(Color.GREEN);
                } else {
                    setBackground(Color.RED);
                }
                if (isSelected) {
                    setForeground(Color.YELLOW);
                } else {
                    setForeground(Color.BLACK);
                }
                return this;
            }
        });

    }
    return rulesTable;
}

From source file:grupob.TipoProceso.java

public TipoProceso() {
    initComponents();/*from   w w w.ja va  2  s.c o  m*/
    initInstitucional();
    //        listaRegiones.add(new Region(1,"Lima",15000));
    //        listaRegiones.add(new Region(1,"Arequipa",10000));
    //        listaRegiones.add(new Region(1,"Junin",12000));
    TipoProcesoVotacion tipoNacional = Manager.queryProcesoById(1);
    TipoProcesoVotacion tipoRegional = Manager.queryProcesoById(2);
    TipoProcesoVotacion tipoDistrital = Manager.queryProcesoById(3);
    Calendar cal = Calendar.getInstance();
    Date dateActual = cal.getTime();
    textConfGeneral.setText(Recorte.rutaGeneral);
    textConfHuellas.setText(Recorte.rutaHuella);
    textConfFirmas.setText(Recorte.rutaFirma);
    /*
    Recorte.rutaGeneral = FramePrincipal.rutaGeneral;
    Recorte.rutaHuella = FramePrincipal.rutaHuella;
    Recorte.rutaFirma = FramePrincipal.rutaFirma;*/

    if (tipoNacional != null && tipoNacional.getId() != 0) {
        if (!tipoNacional.getFechaInicio2().after(dateActual)) {
            fechai1Nacional.setDate(tipoNacional.getFechaInicio1().getTime());
            fechai2Nacional.setDate(tipoNacional.getFechaInicio2().getTime());
            fechaf1Nacional.setDate(tipoNacional.getFechaFin1().getTime());
            fechaf2Nacional.setDate(tipoNacional.getFechaFin2().getTime());
        }
        if ((tipoNacional.getFechaInicio1().before(dateActual)) && (cal.before(tipoNacional.getFechaFin2()))) {
            botonGuardarNacional.setEnabled(false);
        }
        if (tipoNacional.getFechaFin2().before(dateActual)) {
            botonGuardarNacional.setEnabled(true);
        }
    }
    if (tipoRegional != null && tipoRegional.getId() != 0) {
        if (!tipoRegional.getFechaInicio2().after(dateActual)) {
            fechai1Regiones.setDate(tipoRegional.getFechaInicio1().getTime());
            fechai2Regiones.setDate(tipoRegional.getFechaInicio2().getTime());
            fechaf1Regiones.setDate(tipoRegional.getFechaFin1().getTime());
            fechaf2Regiones.setDate(tipoRegional.getFechaFin2().getTime());
            porcentajeRegional.setText("" + tipoRegional.getPorcentajeMinimo() * 100);
        }
        if ((tipoRegional.getFechaInicio1().before(dateActual)) && (cal.before(tipoRegional.getFechaFin2()))) {
            botonGuardarRegional.setEnabled(false);
        }
        if (tipoRegional.getFechaFin2().before(dateActual)) {
            botonGuardarRegional.setEnabled(true);
        }
    }
    if (tipoDistrital != null && tipoDistrital.getId() != 0) {
        if (!tipoRegional.getFechaInicio2().after(dateActual)) {
            fechai1Distritos.setDate(tipoDistrital.getFechaInicio1().getTime());
            fechai2Distritos.setDate(tipoDistrital.getFechaInicio2().getTime());
            fechaf1Distritos.setDate(tipoDistrital.getFechaFin1().getTime());
            fechaf2Distritos.setDate(tipoDistrital.getFechaFin2().getTime());
            porcentajeDistrital.setText("" + tipoDistrital.getPorcentajeMinimo() * 100);
        }
        if ((tipoDistrital.getFechaInicio1().before(dateActual))
                && (cal.before(tipoDistrital.getFechaFin2()))) {
            botonGuardarDistrital.setEnabled(false);
            //                addRowRegional.setEnabled(false);
            //                jTable6.setEnabled(false);
        }
        if (tipoDistrital.getFechaFin2().before(dateActual)) {
            botonGuardarDistrital.setEnabled(true);
            //                addRowRegional.setEnabled(true);
        }
    }
    agregarDatos();
    agregarDatosDistritos();
    if (listaRegiones != null) {
        jTableRegiones.getColumn("Eliminar").setCellRenderer(new ButtonRenderer());
        jTableRegiones.getColumn("Eliminar").setCellEditor(new botonEliminarRegiones());
    }
    if (listaDistritos != null) {
        jTableDistritos.getColumn("Eliminar").setCellRenderer(new ButtonRenderer());
        jTableDistritos.getColumn("Eliminar").setCellEditor(new botonEliminarDistritos());
    }

    TableColumn sColumn = jTableDistritos.getColumnModel().getColumn(2);
    ArrayList<Region> lReg = Manager.queryAllRegion();
    JComboBox comboBox = new JComboBox();
    for (int i = 0; i < lReg.size(); i++) {
        comboBox.addItem(lReg.get(i).getNombre());
    }
    sColumn.setCellEditor(new DefaultCellEditor(comboBox));

    TableColumn instColumn = tblInstitucional.getColumnModel().getColumn(2);
    ArrayList<Local> lLoc = Manager.queryAllLocales();
    JComboBox comboBoxLocal = new JComboBox();
    for (int i = 0; i < lLoc.size(); i++) {
        comboBoxLocal.addItem(lLoc.get(i).getNombre());
    }
    instColumn.setCellEditor(new DefaultCellEditor(comboBoxLocal));

    ChangeListener changeListener = new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {

            JTabbedPane sourceTabbedPane = (JTabbedPane) e.getSource();
            int index = sourceTabbedPane.getSelectedIndex();
            switch (index) {
            case 3:
                cargarDatosLocal();
                return;

            default:
                return;
            }

        }
    };

    jconfiguracion.addChangeListener(changeListener);

}