Example usage for javax.swing JComboBox setBackground

List of usage examples for javax.swing JComboBox setBackground

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.")
public void setBackground(Color bg) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    String[] items = new String[] { "", "Apple", "Banana", "Carrot" };
    Color bgColor = UIManager.getColor("TextField.background");

    UIManager.put("ComboBox.selectionBackground", new ColorUIResource(bgColor));

    JComboBox<String> combo1 = new JComboBox<>(items);
    combo1.setPrototypeDisplayValue("XXXXXXXXXXXXXXX");
    combo1.setEditable(true);/*from w  w w  .j a v  a2  s . c om*/
    combo1.setSelectedIndex(-1);

    JComboBox<String> combo2 = new JComboBox<>(items);
    combo2.setPrototypeDisplayValue("XXXXXXXXXXXXXXX");
    combo2.setEditable(false);
    combo2.setSelectedIndex(-1);
    combo2.setBackground(bgColor);

    JFrame frame = new JFrame();
    Container c = frame.getContentPane();
    c.setLayout(new FlowLayout());
    c.add(combo1);
    c.add(combo2);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 100);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static JComboBox generateComboBoxFor(Object... objs) {
    Container c = search(objs, Container.class);
    ComboBoxModel model = null;/*from  w  w w.  j  ava 2  s.  c  om*/
    Vector items = null;
    Object[] itms = null;
    Border border = search(objs, Border.class);
    Color color = search(objs, Color.class);
    ComboBoxUI ui = search(objs, ComboBoxUI.class);
    JComboBox combo = (model = search(objs, ComboBoxModel.class)) == null
            ? (items = search(objs, Vector.class)) == null ? new JComboBox(itms = search(objs, Object[].class))
                    : new JComboBox(items)
            : new JComboBox(model);
    if (border != null)
        combo.setBorder(border);
    if (ui != null)
        combo.setUI(ui);
    if (color != null)
        combo.setBackground(color);
    addJContainerListeners(combo, objs);
    addToContainer(c, combo);
    return combo;
}

From source file:org.fhaes.fhsamplesize.view.FHSampleSize.java

/**
 * Initialize GUI components.//from   ww  w. ja v  a  2s .co  m
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private void initGUI() {

    App.init();

    // setBounds(100, 100, 972, 439);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setIconImage(Builder.getApplicationIcon());
    setTitle("Sample Size Analysis");
    getContentPane().setLayout(new MigLayout("", "[1136px,grow,fill]", "[30px][405px,grow]"));

    JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);
    getContentPane().add(toolBar, "cell 0 0,growx,aligny top");

    JToolBarButton btnOpen = new JToolBarButton(actionBrowse);
    btnOpen.setIcon(Builder.getImageIcon("fileopen.png"));
    toolBar.add(btnOpen);

    JToolBarButton btnSave = new JToolBarButton(actionSaveTable);
    btnSave.setIcon(Builder.getImageIcon("save.png"));
    toolBar.add(btnSave);

    JToolBarButton btnExportPDF = new JToolBarButton(actionExportPDF);
    btnExportPDF.setIcon(Builder.getImageIcon("pdf.png"));
    toolBar.add(btnExportPDF);

    JToolBarButton btnExportPNG = new JToolBarButton(actionExportPNG);
    btnExportPNG.setIcon(Builder.getImageIcon("formatpng.png"));
    toolBar.add(btnExportPNG);

    toolBar.addSeparator();

    JToolBarButton btnRun = new JToolBarButton(actionRun);
    btnRun.setIcon(Builder.getImageIcon("run.png"));
    toolBar.add(btnRun);

    JPanel panelMain = new JPanel();
    getContentPane().add(panelMain, "cell 0 1,grow");
    panelMain.setLayout(new BorderLayout(0, 0));

    JSplitPane splitPaneMain = new JSplitPane();
    splitPaneMain.setOneTouchExpandable(true);
    panelMain.add(splitPaneMain);

    JPanel panelParameters = new JPanel();
    splitPaneMain.setLeftComponent(panelParameters);
    panelParameters.setLayout(new MigLayout("", "[grow,right]", "[][][][193.00,grow,fill][]"));

    JPanel panelInput = new JPanel();
    panelInput.setBorder(new TitledBorder(null, "Input", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panelParameters.add(panelInput, "cell 0 0,grow");
    panelInput.setLayout(new MigLayout("", "[100px:100px:180px,right][grow,fill][]", "[]"));

    JLabel lblInputFile = new JLabel("Input file:");
    panelInput.add(lblInputFile, "cell 0 0");

    txtInputFile = new JTextField();
    panelInput.add(txtInputFile, "cell 1 0,growx");
    txtInputFile.setActionCommand("NewFileTyped");
    txtInputFile.addActionListener(this);
    txtInputFile.setColumns(10);

    JButton btnBrowse = new JButton("");
    panelInput.add(btnBrowse, "cell 2 0");
    btnBrowse.setAction(actionBrowse);
    btnBrowse.setText("");
    btnBrowse.setIcon(Builder.getImageIcon("fileopen16.png"));
    btnBrowse.setPreferredSize(new Dimension(25, 25));
    btnBrowse.setMaximumSize(new Dimension(25, 25));
    btnBrowse.putClientProperty("JButton.buttonType", "segmentedTextured");
    btnBrowse.putClientProperty("JButton.segmentPosition", "middle");

    JPanel panelAnalysisOptions = new JPanel();
    panelAnalysisOptions.setBorder(new TitledBorder(null, "Analysis and filtering options",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panelParameters.add(panelAnalysisOptions, "cell 0 1,grow");
    panelAnalysisOptions.setLayout(new MigLayout("", "[100px:100px:180px,right][grow][][]", "[][][][][]"));

    JLabel lblEventTypes = new JLabel("Event type:");
    panelAnalysisOptions.add(lblEventTypes, "cell 0 0");

    cboEventType = new JComboBox();
    panelAnalysisOptions.add(cboEventType, "cell 1 0 3 1");
    cboEventType.setModel(new DefaultComboBoxModel(EventTypeToProcess.values()));
    new EventTypeWrapper(cboEventType, PrefKey.EVENT_TYPE_TO_PROCESS, EventTypeToProcess.FIRE_EVENT);

    chkCommonYears = new JCheckBox("<html>Only analyze years all series have in common");
    chkCommonYears.setEnabled(false);
    new CheckBoxWrapper(chkCommonYears, PrefKey.SSIZ_CHK_COMMON_YEARS, false);
    panelAnalysisOptions.add(chkCommonYears, "cell 1 1 3 1");

    chkExcludeSeriesWithNoEvents = new JCheckBox("<html>Exclude series/segments with no events");
    chkExcludeSeriesWithNoEvents.setEnabled(false);
    new CheckBoxWrapper(chkExcludeSeriesWithNoEvents, PrefKey.SSIZ_CHK_EXCLUDE_SERIES_WITH_NO_EVENTS, false);
    panelAnalysisOptions.add(chkExcludeSeriesWithNoEvents, "cell 1 2 3 1");

    JLabel lblThresholdType = new JLabel("Threshold:");
    panelAnalysisOptions.add(lblThresholdType, "cell 0 3");

    cboThresholdType = new JComboBox();
    panelAnalysisOptions.add(cboThresholdType, "cell 1 3");
    cboThresholdType.setModel(new DefaultComboBoxModel(FireFilterType.values()));
    new FireFilterTypeWrapper(cboThresholdType, PrefKey.COMPOSITE_FILTER_TYPE_WITH_ALL_TREES,
            FireFilterType.NUMBER_OF_EVENTS);

    JLabel label = new JLabel(">=");
    panelAnalysisOptions.add(label, "flowx,cell 2 3");

    spnThresholdValueGT = new JSpinner();
    panelAnalysisOptions.add(spnThresholdValueGT, "cell 3 3");
    spnThresholdValueGT.setModel(new SpinnerNumberModel(1, 1, 999, 1));
    new SpinnerWrapper(spnThresholdValueGT, PrefKey.COMPOSITE_FILTER_VALUE, 1);

    chkEnableLessThan = new JCheckBox("");
    chkEnableLessThan.setActionCommand("LessThanThresholdStatus");
    chkEnableLessThan.addActionListener(this);
    panelAnalysisOptions.add(chkEnableLessThan, "flowx,cell 1 4,alignx right");

    lblLessThan = new JLabel("<=");
    lblLessThan.setEnabled(false);
    panelAnalysisOptions.add(lblLessThan, "cell 2 4");

    spnThresholdValueLT = new JSpinner();
    spnThresholdValueLT.setEnabled(false);
    spnThresholdValueLT.setModel(new SpinnerNumberModel(1, 1, 999, 1));
    panelAnalysisOptions.add(spnThresholdValueLT, "cell 3 4");

    lblAnd = new JLabel("and");
    panelAnalysisOptions.add(lblAnd, "cell 1 4");

    JPanel panelSimulations = new JPanel();
    panelSimulations.setBorder(
            new TitledBorder(null, "Simulations", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panelParameters.add(panelSimulations, "cell 0 2,grow");
    panelSimulations.setLayout(new MigLayout("", "[100px:100px:180px,right][fill]", "[][][]"));

    JLabel lblSimulations = new JLabel("Simulations:");
    panelSimulations.add(lblSimulations, "cell 0 0");

    spnSimulations = new JSpinner();
    panelSimulations.add(spnSimulations, "cell 1 0");
    spnSimulations.setModel(new SpinnerNumberModel(new Integer(1000), new Integer(1), null, new Integer(1)));
    new SpinnerWrapper(spnSimulations, PrefKey.SSIZ_SIMULATION_COUNT, 1000);

    JLabel lblSeedNumber = new JLabel("Seed number:");
    panelSimulations.add(lblSeedNumber, "cell 0 1");

    spnSeed = new JSpinner();
    panelSimulations.add(spnSeed, "cell 1 1");
    spnSeed.setModel(new SpinnerNumberModel(new Integer(30188), null, null, new Integer(1)));
    new SpinnerWrapper(spnSeed, PrefKey.SSIZ_SEED_NUMBER, 30188);

    JLabel lblResampling = new JLabel("Resampling:");
    panelSimulations.add(lblResampling, "cell 0 2");

    cboResampling = new JComboBox();
    panelSimulations.add(cboResampling, "cell 1 2");
    cboResampling
            .setModel(new DefaultComboBoxModel(new String[] { "With replacement", "Without replacement" }));
    new ResamplingTypeWrapper(cboResampling, PrefKey.SSIZ_RESAMPLING_TYPE, ResamplingType.WITH_REPLACEMENT);

    segmentationPanel = new SegmentationPanel();
    segmentationPanel.chkSegmentation.setText("Process subset or segments of dataset?");
    segmentationPanel.chkSegmentation.setEnabled(false);
    panelParameters.add(segmentationPanel, "cell 0 3,growx");

    JPanel panel_3 = new JPanel();
    panelParameters.add(panel_3, "cell 0 4,grow");
    panel_3.setLayout(new MigLayout("", "[left][grow][right]", "[]"));

    JButton btnReset = new JButton("Reset");
    btnReset.setActionCommand("Reset");
    btnReset.addActionListener(this);
    panel_3.add(btnReset, "cell 0 0,grow");

    JButton btnRunAnalysis = new JButton("Run Analysis");
    btnRunAnalysis.setAction(actionRun);
    panel_3.add(btnRunAnalysis, "cell 2 0,grow");

    JPanel panelResults = new JPanel();
    splitPaneMain.setRightComponent(panelResults);
    panelResults.setLayout(new BorderLayout(0, 0));

    splitPaneResults = new JSplitPane();
    splitPaneResults.setResizeWeight(0.5);
    splitPaneResults.setOneTouchExpandable(true);
    splitPaneResults.setDividerLocation(0.5d);
    panelResults.add(splitPaneResults, BorderLayout.CENTER);
    splitPaneResults.setOrientation(JSplitPane.VERTICAL_SPLIT);

    JPanel panelResultsTop = new JPanel();
    splitPaneResults.setLeftComponent(panelResultsTop);
    panelResultsTop.setLayout(new BorderLayout(0, 0));

    JPanel panelChartOptions = new JPanel();
    panelChartOptions.setBackground(Color.WHITE);
    panelResultsTop.add(panelChartOptions, BorderLayout.SOUTH);
    panelChartOptions.setLayout(new MigLayout("", "[][][][][][grow][grow]", "[15px,center]"));

    JLabel lblNewLabel = new JLabel("Plot:");
    panelChartOptions.add(lblNewLabel, "cell 0 0,alignx trailing,aligny center");

    cboChartMetric = new JComboBox();
    cboChartMetric.setEnabled(false);
    cboChartMetric.setModel(new DefaultComboBoxModel(MiddleMetric.values()));
    panelChartOptions.add(cboChartMetric, "cell 1 0,growx");
    cboChartMetric.setBackground(Color.WHITE);

    JLabel lblOfSegment = new JLabel("of segment:");
    panelChartOptions.add(lblOfSegment, "cell 2 0,alignx trailing");

    cboSegment = new JComboBox();
    cboSegment.setBackground(Color.WHITE);
    cboSegment.setActionCommand("UpdateChart");
    cboSegment.addActionListener(this);

    panelChartOptions.add(cboSegment, "cell 3 0,growx");
    cboChartMetric.setActionCommand("UpdateChart");

    JLabel lblWithAsymptoteType = new JLabel("with asymptote type:");
    panelChartOptions.add(lblWithAsymptoteType, "cell 4 0,alignx trailing");

    JComboBox comboBox = new JComboBox();
    comboBox.setEnabled(false);
    comboBox.setModel(new DefaultComboBoxModel(new String[] { "none", "Weibull", "Michaelis-Menten",
            "Modified Michaelis-Menten", "Logistic", "Modified exponential" }));
    comboBox.setBackground(Color.WHITE);
    panelChartOptions.add(comboBox, "cell 5 0,growx");
    cboChartMetric.addActionListener(this);

    panelChart = new JPanel();
    panelChart.setMinimumSize(new Dimension(200, 200));
    panelResultsTop.add(panelChart, BorderLayout.CENTER);
    panelChart.setLayout(new BorderLayout(0, 0));
    panelChart.setBackground(Color.WHITE);

    JTabbedPane panelResultsBottom = new JTabbedPane(JTabbedPane.BOTTOM);
    splitPaneResults.setRightComponent(panelResultsBottom);

    simulationsTable = new SSIZResultsTable();
    simulationsTable.setEnabled(false);
    simulationsTable.addMouseListener(new TablePopClickListener());
    simulationsTable.setVisibleRowCount(10);

    adapter = new JTableSpreadsheetByRowAdapter(simulationsTable);

    scrollPaneSimulations = new JScrollPane();
    panelResultsBottom.addTab("Simulations", null, scrollPaneSimulations, null);
    scrollPaneSimulations.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPaneSimulations.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPaneSimulations.setViewportView(simulationsTable);

    JPanel panelAsymptote = new JPanel();

    asymptoteTable = new AsymptoteTable();
    asymptoteTable.setEnabled(false);
    // asymptoteTable.addMouseListener(new TablePopClickListener());
    asymptoteTable.setVisibleRowCount(10);

    scrollPaneAsymptote = new JScrollPane();

    scrollPaneAsymptote.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPaneAsymptote.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPaneAsymptote.setViewportView(asymptoteTable);
    panelAsymptote.setLayout(new BorderLayout());
    panelAsymptote.add(scrollPaneAsymptote, BorderLayout.CENTER);
    panelResultsBottom.addTab("Asymptote", null, panelAsymptote, null);

    // Disable asymptote tab until it is implemented
    panelResultsBottom.setEnabledAt(1, false);

    panelProgressBar = new JPanel();
    panelProgressBar.setLayout(new BorderLayout());

    btnCancelAnalysis = new JButton("Cancel");
    btnCancelAnalysis.setIcon(Builder.getImageIcon("delete.png"));
    btnCancelAnalysis.setVisible(false);
    btnCancelAnalysis.setActionCommand("CancelAnalysis");
    btnCancelAnalysis.addActionListener(this);

    progressBar = new JProgressBar();
    panelProgressBar.add(progressBar, BorderLayout.CENTER);
    panelProgressBar.add(btnCancelAnalysis, BorderLayout.EAST);
    progressBar.setStringPainted(true);

    fileDialogWasUsed = false;
    mouseListenersActive = false;

    this.setGUIForFHFileReader();
    this.setGUIForThresholdStatus();

    pack();
    this.setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
    setVisible(true);
}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private TableCellRenderer getCellRenderer(final SwingTreeCol col) {

    return new DefaultTableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {

            ColumnType colType = col.getColumnType();
            if (colType == ColumnType.DYNAMIC) {
                colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column));
            }//from  w w w . jav  a  2s .c  o  m

            final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column);
            switch (colType) {
            case CHECKBOX:
                JCheckBox checkbox = new JCheckBox();
                if (value instanceof String) {
                    checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$
                } else if (value instanceof Boolean) {
                    checkbox.setSelected((Boolean) value);
                } else if (value == null) {
                    checkbox.setSelected(false);
                }
                if (isSelected) {
                    checkbox.setBackground(Color.LIGHT_GRAY);
                }
                checkbox.setEnabled(!cell.isDisabled());
                return checkbox;
            case COMBOBOX:
            case EDITABLECOMBOBOX:
                Vector data;

                final JComboBox comboBox = new JComboBox();
                if (cell == null) {
                } else {
                    data = (cell.getValue() != null) ? (Vector) cell.getValue() : new Vector();

                    if (data == null) {
                        logger.debug("SwingTreeCell combobox data is null, passed in value: " + value); //$NON-NLS-1$
                        if (value instanceof Vector) {
                            data = (Vector) value;
                        }
                    }
                    if (data != null) {
                        comboBox.setModel(new DefaultComboBoxModel(data));
                        try {
                            comboBox.setSelectedIndex(cell.getSelectedIndex());
                        } catch (Exception e) {
                            logger.error("error setting selected index on the combobox editor"); //$NON-NLS-1$
                        }
                    }
                }

                if (colType == ColumnType.EDITABLECOMBOBOX) {
                    comboBox.setEditable(true);
                    ((JTextComponent) comboBox.getEditor().getEditorComponent()).setText(cell.getLabel());
                }

                if (isSelected) {
                    comboBox.setBackground(Color.LIGHT_GRAY);
                }
                comboBox.setEnabled(!cell.isDisabled());
                return comboBox;
            case CUSTOM:
                return new CustomCellEditorWrapper(cell, customEditors.get(col.getType()));
            default:
                JLabel label = new JLabel((String) value);

                if (isSelected) {
                    label.setOpaque(true);
                    label.setBackground(Color.LIGHT_GRAY);
                }
                return label;
            }

        }
    };

}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private TableCellEditor getCellEditor(final SwingTreeCol col) {
    return new DefaultCellEditor(new JComboBox()) {

        JComponent control;/*from w ww.  j  a va 2s.  co  m*/

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
                final int row, final int column) {
            Component comp;
            ColumnType colType = col.getColumnType();
            if (colType == ColumnType.DYNAMIC) {
                colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column));
            }

            final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column);
            switch (colType) {
            case CHECKBOX:
                final JCheckBox checkbox = new JCheckBox();
                final JTable tbl = table;
                checkbox.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        SwingTree.this.table.setValueAt(checkbox.isSelected(), row, column);
                        tbl.getCellEditor().stopCellEditing();
                    }
                });

                control = checkbox;
                if (value instanceof String) {
                    checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$
                } else if (value instanceof Boolean) {
                    checkbox.setSelected((Boolean) value);
                } else if (value == null) {
                    checkbox.setSelected(false);
                }
                if (isSelected) {
                    checkbox.setBackground(Color.LIGHT_GRAY);
                }
                comp = checkbox;
                checkbox.setEnabled(!cell.isDisabled());
                break;
            case EDITABLECOMBOBOX:
            case COMBOBOX:
                Vector val = (value != null && value instanceof Vector) ? (Vector) value : new Vector();
                final JComboBox comboBox = new JComboBox(val);

                if (isSelected) {
                    comboBox.setBackground(Color.LIGHT_GRAY);
                }

                if (colType == ColumnType.EDITABLECOMBOBOX) {

                    comboBox.setEditable(true);
                    final JTextComponent textComp = (JTextComponent) comboBox.getEditor().getEditorComponent();

                    textComp.addKeyListener(new KeyListener() {
                        private String oldValue = ""; //$NON-NLS-1$

                        public void keyPressed(KeyEvent e) {
                            oldValue = textComp.getText();
                        }

                        public void keyReleased(KeyEvent e) {
                            if (oldValue != null && !oldValue.equals(textComp.getText())) {
                                SwingTree.this.table.setValueAt(textComp.getText(), row, column);

                                oldValue = textComp.getText();
                            } else if (oldValue == null) {
                                // AWT error where sometimes the keyReleased is fired before keyPressed.
                                oldValue = textComp.getText();
                            } else {
                                logger.debug("Special key pressed, ignoring"); //$NON-NLS-1$
                            }
                        }

                        public void keyTyped(KeyEvent e) {
                        }
                    });

                    comboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent event) {
                            // if(textComp.hasFocus() == false && comboBox.hasFocus()){
                            SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$
                                    + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$

                            SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column);
                            // }
                        }
                    });
                } else {
                    comboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent event) {

                            SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$
                                    + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$

                            SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column);
                        }
                    });
                }

                control = comboBox;
                comboBox.setEnabled(!cell.isDisabled());
                comp = comboBox;
                break;
            case LABEL:
                JLabel lbl = new JLabel(cell.getLabel());
                comp = lbl;
                control = lbl;
                break;
            case CUSTOM:
                return new CustomCellEditorWrapper(cell, customEditors.get(col.getType()));
            default:
                final JTextField label = new JTextField((String) value);

                label.getDocument().addDocumentListener(new DocumentListener() {

                    public void changedUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                    public void insertUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                    public void removeUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                });
                if (isSelected) {
                    label.setOpaque(true);
                    // label.setBackground(Color.LIGHT_GRAY);
                }

                control = label;
                comp = label;
                label.setEnabled(!cell.isDisabled());
                label.setDisabledTextColor(Color.DARK_GRAY);
                break;
            }

            return comp;
        }

        @Override
        public Object getCellEditorValue() {
            if (control instanceof JCheckBox) {
                return ((JCheckBox) control).isSelected();
            } else if (control instanceof JComboBox) {
                JComboBox box = (JComboBox) control;
                if (box.isEditable()) {
                    return ((JTextComponent) box.getEditor().getEditorComponent()).getText();
                } else {
                    return box.getSelectedIndex();
                }
            } else if (control instanceof JTextField) {
                return ((JTextField) control).getText();
            } else {
                return ((JLabel) control).getText();
            }
        }

    };

}

From source file:wigraph.ShortestPathRelation.java

private Component getSelectionBox(final boolean from) {

    Set<String> s = new TreeSet<String>();

    for (String v : mGraph.getVertices()) {
        s.add(v);//w  ww.  jav  a  2s.c om
    }
    final JComboBox choices = new JComboBox(s.toArray());
    choices.setSelectedIndex(-1);
    choices.setBackground(Color.WHITE);
    choices.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String v = (String) choices.getSelectedItem();

            if (from) {
                mFrom = v;
            } else {
                mTo = v;
            }
            drawShortest();
            repaint();
        }
    });
    return choices;
}