Example usage for javax.swing JComboBox setBorder

List of usage examples for javax.swing JComboBox setBorder

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.")
public void setBorder(Border border) 

Source Link

Document

Sets the border of this component.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame window = new JFrame("Example");

    JPanel contentPane = new JPanel();

    contentPane.setLayout(new GridBagLayout());

    JComboBox comboBoxfields = new JComboBox(COMBO_BOX_ELEMENTS);

    comboBoxfields.setFont(new Font("sansserif", Font.TRUETYPE_FONT | Font.PLAIN, 15));
    comboBoxfields.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));

    comboBoxfields.setMaximumRowCount(5);

    comboBoxfields.addActionListener(/*from  w  w  w.j a v a  2 s.  c o  m*/
            e -> System.out.println("'" + comboBoxfields.getSelectedItem().toString() + "'" + " was selected"));

    contentPane.add(comboBoxfields);

    window.add(contentPane);
    window.setSize(500, 500);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
}

From source file:Main.java

public static JComboBox generateComboBoxFor(Object... objs) {
    Container c = search(objs, Container.class);
    ComboBoxModel model = null;//ww  w  .  j  av a2 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:lu.lippmann.cdb.datasetview.tabs.ScatterPlotTabView.java

private void update0(final Instances dataSet, int xidx, int yidx, int coloridx, final boolean asSerie) {
    System.out.println(xidx + " " + yidx);

    this.panel.removeAll();

    if (xidx == -1)
        xidx = 0;//from   w  ww  . ja  v a  2s  .com
    if (yidx == -1)
        yidx = 1;
    if (coloridx == -1)
        coloridx = 0;

    final Object[] numericAttrNames = WekaDataStatsUtil.getNumericAttributesNames(dataSet).toArray();

    final JComboBox xCombo = new JComboBox(numericAttrNames);
    xCombo.setBorder(new TitledBorder("x"));
    xCombo.setSelectedIndex(xidx);
    final JComboBox yCombo = new JComboBox(numericAttrNames);
    yCombo.setBorder(new TitledBorder("y"));
    yCombo.setSelectedIndex(yidx);
    final JCheckBox jcb = new JCheckBox("Draw lines");
    jcb.setSelected(asSerie);
    final JComboBox colorCombo = new JComboBox(numericAttrNames);
    colorCombo.setBorder(new TitledBorder("color"));
    colorCombo.setSelectedIndex(coloridx);
    colorCombo.setVisible(dataSet.classIndex() < 0);

    xCombo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            update0(dataSet, xCombo.getSelectedIndex(), yCombo.getSelectedIndex(),
                    colorCombo.getSelectedIndex(), jcb.isSelected());
        }
    });

    yCombo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            update0(dataSet, xCombo.getSelectedIndex(), yCombo.getSelectedIndex(),
                    colorCombo.getSelectedIndex(), jcb.isSelected());
        }
    });

    colorCombo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            update0(dataSet, xCombo.getSelectedIndex(), yCombo.getSelectedIndex(),
                    colorCombo.getSelectedIndex(), jcb.isSelected());
        }
    });

    jcb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            update0(dataSet, xCombo.getSelectedIndex(), yCombo.getSelectedIndex(),
                    colorCombo.getSelectedIndex(), jcb.isSelected());
        }
    });

    final JXPanel comboPanel = new JXPanel();
    comboPanel.setLayout(new GridLayout(1, 0));
    comboPanel.add(xCombo);
    comboPanel.add(yCombo);
    comboPanel.add(colorCombo);
    comboPanel.add(jcb);
    this.panel.add(comboPanel, BorderLayout.NORTH);

    final java.util.List<Integer> numericAttrIdx = WekaDataStatsUtil.getNumericAttributesIndexes(dataSet);
    final ChartPanel scatterplotChartPanel = buildChartPanel(dataSet, numericAttrIdx.get(xidx),
            numericAttrIdx.get(yidx), numericAttrIdx.get(coloridx), asSerie);

    this.panel.add(scatterplotChartPanel, BorderLayout.CENTER);

    this.panel.repaint();
    this.panel.updateUI();
}

From source file:projects.wdlf47tuc.ProcessAllSwathcal.java

/**
 * Main entry point./*from   www .  ja  v  a  2s  .c o  m*/
 * 
 * @param args
 * 
 * @throws IOException 
 * 
 */
public ProcessAllSwathcal() {

    // Path to AllSwathcal.dat file
    File allSwathcal = new File(
            "/home/nrowell/Astronomy/Data/47_Tuc/Kalirai_2012/UVIS/www.stsci.edu/~jkalirai/47Tuc/AllSwathcal.dat");

    // Read file contents into the List
    try (BufferedReader in = new BufferedReader(new FileReader(allSwathcal))) {
        String sourceStr;
        while ((sourceStr = in.readLine()) != null) {
            Source source = Source.parseSource(sourceStr);
            if (source != null) {
                allSources.add(source);
            }
        }
    } catch (IOException e) {
    }

    logger.info("Parsed " + allSources.size() + " Sources from AllSwathcal.dat");

    // Initialise chart
    cmdPanel = new ChartPanel(updateDataAndPlotCmd(allSources));
    cmdPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent e) {
            // Capture mouse click location, transform to graph coordinates and add
            // a point to the polygonal selection box.
            Point2D p = cmdPanel.translateScreenToJava2D(e.getTrigger().getPoint());
            Rectangle2D plotArea = cmdPanel.getScreenDataArea();
            XYPlot plot = (XYPlot) cmdPanel.getChart().getPlot();
            double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
            double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
            points.add(new double[] { chartX, chartY });
            cmdPanel.setChart(plotCmd());
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent arg0) {
        }
    });

    // Create colour combo boxes
    final JComboBox<Filter> magComboBox = new JComboBox<Filter>(filters);
    final JComboBox<Filter> col1ComboBox = new JComboBox<Filter>(filters);
    final JComboBox<Filter> col2ComboBox = new JComboBox<Filter>(filters);

    // Set initial values
    magComboBox.setSelectedItem(magFilter);
    col1ComboBox.setSelectedItem(col1Filter);
    col2ComboBox.setSelectedItem(col2Filter);

    // Create an action listener for these
    ActionListener al = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == magComboBox) {
                magFilter = (Filter) magComboBox.getSelectedItem();
            }
            if (evt.getSource() == col1ComboBox) {
                col1Filter = (Filter) col1ComboBox.getSelectedItem();
            }
            if (evt.getSource() == col2ComboBox) {
                col2Filter = (Filter) col2ComboBox.getSelectedItem();
            }
            // Changed colour(s), so reset selection box coordinates
            points.clear();
            cmdPanel.setChart(updateDataAndPlotCmd(allSources));
        }
    };
    magComboBox.addActionListener(al);
    col1ComboBox.addActionListener(al);
    col2ComboBox.addActionListener(al);
    // Add a bit of padding to space things out
    magComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));
    col1ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));
    col2ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Set up statistic sliders
    final JSlider magErrMaxSlider = GuiUtil.buildSlider(magErrorRangeMin, magErrorRangeMax, 3, "%3.3f");
    final JSlider chi2MaxSlider = GuiUtil.buildSlider(chi2RangeMin, chi2RangeMax, 3, "%3.3f");
    final JSlider sharpMinSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f");
    final JSlider sharpMaxSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f");

    // Set intial values
    magErrMaxSlider.setValue(
            (int) Math.rint(100.0 * (magErrMax - magErrorRangeMin) / (magErrorRangeMax - magErrorRangeMin)));
    chi2MaxSlider.setValue((int) Math.rint(100.0 * (chi2Max - chi2RangeMin) / (chi2RangeMax - chi2RangeMin)));
    sharpMinSlider
            .setValue((int) Math.rint(100.0 * (sharpMin - sharpRangeMin) / (sharpRangeMax - sharpRangeMin)));
    sharpMaxSlider
            .setValue((int) Math.rint(100.0 * (sharpMax - sharpRangeMin) / (sharpRangeMax - sharpRangeMin)));

    // Set labels & initial values
    final JLabel magErrMaxLabel = new JLabel(getMagErrMaxLabel());
    final JLabel chi2MaxLabel = new JLabel(getChi2MaxLabel());
    final JLabel sharpMinLabel = new JLabel(getSharpMinLabel());
    final JLabel sharpMaxLabel = new JLabel(getSharpMaxLabel());

    // Create a change listener fot these
    ChangeListener cl = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();

            if (source == magErrMaxSlider) {
                // Compute max mag error from slider position
                double newMagErrMax = magErrorRangeMin
                        + (magErrorRangeMax - magErrorRangeMin) * (source.getValue() / 100.0);
                magErrMax = newMagErrMax;
                magErrMaxLabel.setText(getMagErrMaxLabel());
            }
            if (source == chi2MaxSlider) {
                // Compute Chi2 max from slider position
                double newChi2Max = chi2RangeMin + (chi2RangeMax - chi2RangeMin) * (source.getValue() / 100.0);
                chi2Max = newChi2Max;
                chi2MaxLabel.setText(getChi2MaxLabel());
            }
            if (source == sharpMinSlider) {
                // Compute sharp min from slider position
                double newSharpMin = sharpRangeMin
                        + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0);
                sharpMin = newSharpMin;
                sharpMinLabel.setText(getSharpMinLabel());
            }
            if (source == sharpMaxSlider) {
                // Compute sharp max from slider position
                double newSharpMax = sharpRangeMin
                        + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0);
                sharpMax = newSharpMax;
                sharpMaxLabel.setText(getSharpMaxLabel());
            }
            cmdPanel.setChart(updateDataAndPlotCmd(allSources));
        }
    };
    magErrMaxSlider.addChangeListener(cl);
    chi2MaxSlider.addChangeListener(cl);
    sharpMinSlider.addChangeListener(cl);
    sharpMaxSlider.addChangeListener(cl);
    // Add a bit of padding to space things out
    magErrMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    chi2MaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    sharpMinSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    sharpMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Text field to store distance modulus
    final JTextField distanceModulusField = new JTextField(Double.toString(mu));
    distanceModulusField.setBorder(new EmptyBorder(5, 5, 5, 5));

    Border compound = BorderFactory.createCompoundBorder(new LineBorder(this.getBackground(), 5),
            BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

    final JButton lfButton = new JButton("Luminosity function for selection");
    lfButton.setBorder(compound);
    lfButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            // Read distance modulus field
            try {
                double mu_new = Double.parseDouble(distanceModulusField.getText());
                mu = mu_new;
            } catch (NullPointerException | NumberFormatException ex) {
                JOptionPane.showMessageDialog(lfButton,
                        "Error parsing the distance modulus: " + ex.getMessage(), "Distance Modulus Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (boxedSources.isEmpty()) {
                JOptionPane.showMessageDialog(lfButton, "No sources are currently selected!", "Selection Error",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                computeAndPlotLuminosityFunction(boxedSources);
            }
        }
    });
    final JButton clearSelectionButton = new JButton("Clear selection");
    clearSelectionButton.setBorder(compound);
    clearSelectionButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            points.clear();
            cmdPanel.setChart(plotCmd());
        }
    });

    JPanel controls = new JPanel(new GridLayout(9, 2));
    controls.setBorder(new EmptyBorder(10, 10, 10, 10));
    controls.add(new JLabel("Magnitude = "));
    controls.add(magComboBox);
    controls.add(new JLabel("Colour 1 = "));
    controls.add(col1ComboBox);
    controls.add(new JLabel("Colour 2 = "));
    controls.add(col2ComboBox);
    controls.add(magErrMaxLabel);
    controls.add(magErrMaxSlider);
    controls.add(chi2MaxLabel);
    controls.add(chi2MaxSlider);
    controls.add(sharpMinLabel);
    controls.add(sharpMinSlider);
    controls.add(sharpMaxLabel);
    controls.add(sharpMaxSlider);
    controls.add(new JLabel("Adopted distance modulus = "));
    controls.add(distanceModulusField);
    controls.add(lfButton);
    controls.add(clearSelectionButton);

    this.setLayout(new BorderLayout());
    this.add(cmdPanel, BorderLayout.CENTER);
    this.add(controls, BorderLayout.SOUTH);

    this.validate();
}

From source file:org.apache.cayenne.modeler.editor.ObjEntityRelationshipPanel.java

protected void rebuildTable(ObjEntity entity) {
    final ObjRelationshipTableModel model = new ObjRelationshipTableModel(entity, mediator, this);

    model.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (table.getSelectedRow() >= 0) {
                ObjRelationship rel = model.getRelationship(table.getSelectedRow());
                enabledResolve = rel.getSourceEntity().getDbEntity() != null;
                resolveMenu.setEnabled(enabledResolve);
            }//from  w w w. j  a v a2s.c o  m
        }
    });

    table.setModel(model);
    table.setRowHeight(25);
    table.setRowMargin(3);

    TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET_PATH);
    col.setCellEditor(new DbRelationshipPathComboBoxEditor());
    col.setCellRenderer(new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
            setToolTipText(
                    "To choose relationship press enter two times.To choose next relationship press dot.");
            return this;
        }
    });

    col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_DELETE_RULE);
    JComboBox deleteRulesCombo = Application.getWidgetFactory().createComboBox(DELETE_RULES, false);
    deleteRulesCombo.setFocusable(false);
    deleteRulesCombo.setEditable(true);
    ((JComponent) deleteRulesCombo.getEditor().getEditorComponent()).setBorder(null);
    deleteRulesCombo.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    deleteRulesCombo.setSelectedIndex(0); // Default to the first value
    col.setCellEditor(Application.getWidgetFactory().createCellEditor(deleteRulesCombo));

    tablePreferences.bind(table, null, null, null, ObjRelationshipTableModel.REL_NAME, true);
}