Example usage for javax.swing JComboBox JComboBox

List of usage examples for javax.swing JComboBox JComboBox

Introduction

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

Prototype

public JComboBox(Vector<E> items) 

Source Link

Document

Creates a JComboBox that contains the elements in the specified Vector.

Usage

From source file:components.SharedModelDemo.java

public SharedModelDemo() {
    super(new BorderLayout());

    Vector data = new Vector(7);
    String[] columnNames = { "French", "Spanish", "Italian" };
    String[] oneData = { "un", "uno", "uno" };
    String[] twoData = { "deux", "dos", "due" };
    String[] threeData = { "trois", "tres", "tre" };
    String[] fourData = { "quatre", "cuatro", "quattro" };
    String[] fiveData = { "cinq", "cinco", "cinque" };
    String[] sixData = { "six", "seis", "sei" };
    String[] sevenData = { "sept", "siete", "sette" };

    //Build the model.
    SharedDataModel dataModel = new SharedDataModel(columnNames);
    dataModel.addElement(oneData);/*w  ww  .  j  av a 2s.c  o m*/
    dataModel.addElement(twoData);
    dataModel.addElement(threeData);
    dataModel.addElement(fourData);
    dataModel.addElement(fiveData);
    dataModel.addElement(sixData);
    dataModel.addElement(sevenData);

    list = new JList(dataModel);
    list.setCellRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList l, Object value, int i, boolean s, boolean f) {
            String[] array = (String[]) value;
            return super.getListCellRendererComponent(l, array[0], i, s, f);
        }
    });

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    JScrollPane listPane = new JScrollPane(list);

    table = new JTable(dataModel);
    table.setSelectionModel(listSelectionModel);
    JScrollPane tablePane = new JScrollPane(table);

    //Build control area (use default FlowLayout).
    JPanel controlPane = new JPanel();
    String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
                listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
        }
    });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    //Build output area.
    output = new JTextArea(10, 40);
    output.setEditable(false);
    JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    //Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.X_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    listContainer.setBorder(BorderFactory.createTitledBorder("List"));
    listContainer.add(listPane);
    JPanel tableContainer = new JPanel(new GridLayout(1, 1));
    tableContainer.setBorder(BorderFactory.createTitledBorder("Table"));
    tableContainer.add(tablePane);
    tablePane.setPreferredSize(new Dimension(300, 100));
    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(400, 50));
    topHalf.setPreferredSize(new Dimension(400, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.NORTH);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    //XXX: next line needed if bottomHalf is a scroll pane:
    //bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 135));
    splitPane.add(bottomHalf);
}

From source file:hspc.submissionsprogram.AppDisplay.java

AppDisplay() {
    this.setTitle("Dominion High School Programming Contest");
    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    this.setResizable(false);

    WindowListener exitListener = new WindowAdapter() {
        @Override/*w w  w . j a va 2  s  .  com*/
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    this.addWindowListener(exitListener);

    JTabbedPane pane = new JTabbedPane();
    this.add(pane);

    JPanel submitPanel = new JPanel(null);
    submitPanel.setPreferredSize(new Dimension(500, 500));

    UIManager.put("FileChooser.readOnly", true);
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setBounds(0, 0, 500, 350);
    fileChooser.setVisible(true);
    FileNameExtensionFilter javaFilter = new FileNameExtensionFilter("Java files (*.java)", "java");
    fileChooser.setFileFilter(javaFilter);
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setControlButtonsAreShown(false);
    submitPanel.add(fileChooser);

    JSeparator separator1 = new JSeparator();
    separator1.setBounds(12, 350, 476, 2);
    separator1.setForeground(new Color(122, 138, 152));
    submitPanel.add(separator1);

    JLabel problemChooserLabel = new JLabel("Problem:");
    problemChooserLabel.setBounds(12, 360, 74, 25);
    submitPanel.add(problemChooserLabel);

    String[] listOfProblems = Main.Configuration.get("problem_names")
            .split(Main.Configuration.get("name_delimiter"));
    JComboBox problems = new JComboBox<>(listOfProblems);
    problems.setBounds(96, 360, 393, 25);
    submitPanel.add(problems);

    JButton submit = new JButton("Submit");
    submit.setBounds(170, 458, 160, 30);
    submit.addActionListener(e -> {
        try {
            File file = fileChooser.getSelectedFile();
            try {
                CloseableHttpClient httpClient = HttpClients.createDefault();
                HttpPost uploadFile = new HttpPost(Main.Configuration.get("submit_url"));

                MultipartEntityBuilder builder = MultipartEntityBuilder.create();
                builder.addTextBody("accountID", Main.accountID, ContentType.TEXT_PLAIN);
                builder.addTextBody("problem", String.valueOf(problems.getSelectedItem()),
                        ContentType.TEXT_PLAIN);
                builder.addBinaryBody("submission", file, ContentType.APPLICATION_OCTET_STREAM, file.getName());
                HttpEntity multipart = builder.build();

                uploadFile.setEntity(multipart);

                CloseableHttpResponse response = httpClient.execute(uploadFile);
                HttpEntity responseEntity = response.getEntity();
                String inputLine;
                BufferedReader br = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
                try {
                    if ((inputLine = br.readLine()) != null) {
                        int rowIndex = Integer.parseInt(inputLine);
                        new ResultWatcher(rowIndex);
                    }
                    br.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(this, "No file selected.\nPlease select a java file.", "Error",
                    JOptionPane.WARNING_MESSAGE);
        }
    });
    submitPanel.add(submit);

    JPanel clarificationsPanel = new JPanel(null);
    clarificationsPanel.setPreferredSize(new Dimension(500, 500));

    cList = new JList<>();
    cList.setBounds(12, 12, 476, 200);
    cList.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)),
            BorderFactory.createEmptyBorder(8, 8, 8, 8)));
    cList.setBackground(new Color(254, 254, 255));
    clarificationsPanel.add(cList);

    JButton viewC = new JButton("View");
    viewC.setBounds(12, 224, 232, 25);
    viewC.addActionListener(e -> {
        if (cList.getSelectedIndex() != -1) {
            int id = Integer.parseInt(cList.getSelectedValue().split("\\.")[0]);
            clarificationDatas.stream().filter(data -> data.getId() == id).forEach(
                    data -> new ClarificationDisplay(data.getProblem(), data.getText(), data.getResponse()));
        }
    });
    clarificationsPanel.add(viewC);

    JButton refreshC = new JButton("Refresh");
    refreshC.setBounds(256, 224, 232, 25);
    refreshC.addActionListener(e -> updateCList(true));
    clarificationsPanel.add(refreshC);

    JSeparator separator2 = new JSeparator();
    separator2.setBounds(12, 261, 476, 2);
    separator2.setForeground(new Color(122, 138, 152));
    clarificationsPanel.add(separator2);

    JLabel problemChooserLabelC = new JLabel("Problem:");
    problemChooserLabelC.setBounds(12, 273, 74, 25);
    clarificationsPanel.add(problemChooserLabelC);

    JComboBox problemsC = new JComboBox<>(listOfProblems);
    problemsC.setBounds(96, 273, 393, 25);
    clarificationsPanel.add(problemsC);

    JTextArea textAreaC = new JTextArea();
    textAreaC.setLineWrap(true);
    textAreaC.setWrapStyleWord(true);
    textAreaC.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)),
            BorderFactory.createEmptyBorder(8, 8, 8, 8)));
    textAreaC.setBackground(new Color(254, 254, 255));

    JScrollPane areaScrollPane = new JScrollPane(textAreaC);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setBounds(12, 312, 477, 134);
    clarificationsPanel.add(areaScrollPane);

    JButton submitC = new JButton("Submit Clarification");
    submitC.setBounds(170, 458, 160, 30);
    submitC.addActionListener(e -> {
        if (textAreaC.getText().length() > 2048) {
            JOptionPane.showMessageDialog(this,
                    "Clarification body is too long.\nMaximum of 2048 characters allowed.", "Error",
                    JOptionPane.WARNING_MESSAGE);
        } else if (textAreaC.getText().length() < 20) {
            JOptionPane.showMessageDialog(this,
                    "Clarification body is too short.\nClarifications must be at least 20 characters, but no more than 2048.",
                    "Error", JOptionPane.WARNING_MESSAGE);
        } else {
            Connection conn = null;
            PreparedStatement stmt = null;
            try {
                Class.forName(JDBC_DRIVER);

                conn = DriverManager.getConnection(Main.Configuration.get("jdbc_mysql_address"),
                        Main.Configuration.get("mysql_user"), Main.Configuration.get("mysql_pass"));

                String sql = "INSERT INTO clarifications (team, problem, text) VALUES (?, ?, ?)";
                stmt = conn.prepareStatement(sql);

                stmt.setInt(1, Integer.parseInt(String.valueOf(Main.accountID)));
                stmt.setString(2, String.valueOf(problemsC.getSelectedItem()));
                stmt.setString(3, String.valueOf(textAreaC.getText()));

                textAreaC.setText("");

                stmt.executeUpdate();

                stmt.close();
                conn.close();

                updateCList(false);
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (stmt != null) {
                        stmt.close();
                    }
                } catch (Exception ex2) {
                    ex2.printStackTrace();
                }
                try {
                    if (conn != null) {
                        conn.close();
                    }
                } catch (Exception ex2) {
                    ex2.printStackTrace();
                }
            }
        }
    });
    clarificationsPanel.add(submitC);

    pane.addTab("Submit", submitPanel);
    pane.addTab("Clarifications", clarificationsPanel);

    Timer timer = new Timer();
    TimerTask updateTask = new TimerTask() {
        @Override
        public void run() {
            updateCList(false);
        }
    };
    timer.schedule(updateTask, 10000, 10000);

    updateCList(false);

    this.pack();
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}

From source file:com.emental.mindraider.ui.dialogs.ConnectUriqaServerJDialog.java

/**
 * Constructor.//  w w w  .  j  a  va  2 s.c om
 */
public ConnectUriqaServerJDialog() {
    super(Messages.getString("ConnectUriqaServerJDialog.title"));
    getContentPane().setLayout(new BorderLayout());

    // north
    JPanel north = new JPanel();
    north.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.serverUrl")));

    uriqaServerUrl = new JTextField("http://sw.nokia.com/uriqa/", 31);
    uriqaServerUrl.setMinimumSize(new Dimension(TEXT_AREAS_WIDTH, uriqaServerUrl.getPreferredSize().height));
    uriqaServerUrl.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                connect();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    north.add(uriqaServerUrl);
    getContentPane().add(north, BorderLayout.NORTH);

    // center
    JPanel center = new JPanel();
    center.setLayout(new BorderLayout());

    JPanel centerTop = new JPanel();
    centerTop.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.resource")));
    String[] knowUriqaUris = new String[] { "http://sw.nokia.com/VOC-1/term", "http://sw.nokia.com/MARS-3/Rank",
            "http://sw.nokia.com/MARS-3", "http://sw.nokia.com/schemas/nokia/MARS-3.1.rdf" };
    resourceUri = new JComboBox(knowUriqaUris);
    resourceUri.setMinimumSize(new Dimension(TEXT_AREAS_WIDTH, resourceUri.getPreferredSize().height));
    resourceUri.setEditable(true);
    centerTop.add(resourceUri);

    JPanel centerCenter = new JPanel();
    centerCenter.setLayout(new FlowLayout(FlowLayout.LEFT));
    centerCenter.setToolTipText(Messages.getString("ConnectUriqaServerJDialog.loadOverToolTip"));
    centerCenter.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.loadOver")));
    JCheckBox loadOver = new JCheckBox();
    loadOver.setSelected(true);
    loadOver.setEnabled(false);
    centerCenter.add(loadOver);

    JPanel centerBottom = new JPanel();
    centerBottom.setLayout(new FlowLayout(FlowLayout.LEFT));
    centerBottom.setToolTipText(Messages.getString("ConnectUriqaServerJDialog.addInferedToolTip"));
    centerBottom.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.addInfered")));
    addInfered = new JCheckBox();
    addInfered.setSelected(true);
    centerBottom.add(addInfered);

    center.add(centerTop, BorderLayout.NORTH);
    center.add(centerCenter, BorderLayout.CENTER);
    center.add(centerBottom, BorderLayout.SOUTH);
    getContentPane().add(center, BorderLayout.CENTER);

    // south
    JPanel south = new JPanel();
    JButton uploadButton = new JButton(Messages.getString("ConnectUriqaServerJDialog.connect"));
    uploadButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            connect();
        }
    });
    south.add(uploadButton);

    JButton cancelButton = new JButton(Messages.getString("ConnectUriqaServerJDialog.cancel"));
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    south.add(cancelButton);
    getContentPane().add(south, BorderLayout.SOUTH);

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:com.rapidminer.gui.plotter.charts.AbstractBarChartPlotter.java

public AbstractBarChartPlotter() {
    super();/*from   www.  j  a  v  a2s  .  c o m*/
    setBackground(Color.white);

    useDistinct.setToolTipText("Indicates if only distinct values should be used for aggregation functions.");
    useDistinct.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            repaint();
        }
    });

    String[] allFunctions = new String[AggregationOperator.KNOWN_AGGREGATION_FUNCTION_NAMES.length + 1];
    allFunctions[0] = "none";
    System.arraycopy(AggregationOperator.KNOWN_AGGREGATION_FUNCTION_NAMES, 0, allFunctions, 1,
            AggregationOperator.KNOWN_AGGREGATION_FUNCTION_NAMES.length);
    aggregationFunction = new JComboBox(allFunctions);
    aggregationFunction.setToolTipText(
            "Select the type of the aggregation function which should be used for grouped values.");
    aggregationFunction.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            repaint();
        }
    });
}

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

@SuppressWarnings("unchecked")
@Override//from w ww .  j  a  va 2 s .  com
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:au.com.jwatmuff.eventmanager.gui.admin.WithdrawPlayerDialog.java

/** Creates new form WithdrawPlayerDialog */
public WithdrawPlayerDialog(java.awt.Frame parent, boolean modal, Database database,
        TransactionNotifier notifier) {/*from   ww w . ja  v  a  2  s. 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:jmemorize.gui.swing.panels.HistoryChartPanel.java

private JPanel buildChartChooser() {
    JComboBox comboBox = new JComboBox(new String[] { Localization.get(LC.HISTORY_RECENT),
            Localization.get(LC.HISTORY_BY_DATE), Localization.get(LC.HISTORY_BY_WEEK),
            Localization.get(LC.HISTORY_BY_MONTH), Localization.get(LC.HISTORY_BY_YEAR), });

    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox box = (JComboBox) e.getSource();
            m_mode = box.getSelectedIndex();
            updateDataSet();//from  w w  w.  ja v  a2 s. c om
        }
    });

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(comboBox, BorderLayout.WEST);

    return panel;
}

From source file:geneticalgorithm.gui.view.VExperiment.java

public VExperiment() {
    setLayout(new BorderLayout());
    setSize(900, 700);//from  w  ww.jav  a 2 s .  c  om
    setLocationRelativeTo(this);
    setResizable(false);
    buttons = new ArrayList<JButton>();

    // CENTER

    pnlCentral = new JPanel();
    pnlCentral.setLayout(new MigLayout());
    add(pnlCentral, BorderLayout.CENTER);

    lblLocale = new JLabel();
    cmbModelSelectLocale = new DefaultComboBoxModel<String>();
    cmbSelectLocale = new JComboBox<String>(cmbModelSelectLocale);

    lblLimLow = new JLabel();
    spiLow = new JSpinner();
    spiLow.setModel(new SpinnerNumberModel(-10., -100000., 100000., .5));

    lblLimUp = new JLabel();
    spiUp = new JSpinner();
    spiUp.setModel(new SpinnerNumberModel(10., -100000., 100000., .5));

    lblChromosome = new JLabel();
    spiChromosome = new JSpinner();
    spiChromosome.setModel(new SpinnerNumberModel(10, 0, 63, 1));

    lblPopulation = new JLabel();
    spiPopulation = new JSpinner();
    spiPopulation.setModel(new SpinnerNumberModel(10, 0, 100000, 1));

    lblGenerations = new JLabel();
    spiGenerations = new JSpinner();
    spiGenerations.setModel(new SpinnerNumberModel(100, 0, 100000, 1));

    lblProbCrossover = new JLabel();
    txtProbCrossover = new JTextField("0.5");

    lblProbMutation = new JLabel();
    txtProbMutation = new JTextField("0.001");

    lblIndividual = new JLabel();
    cmbModelIndividual = new DefaultComboBoxModel<ClassWrapper>();
    cmbIndividual = new JComboBox<ClassWrapper>(cmbModelIndividual);

    lblCrossover = new JLabel();
    cmbModelCrossover = new DefaultComboBoxModel<ClassWrapper>();
    cmbCrossover = new JComboBox<ClassWrapper>(cmbModelCrossover);

    lblMutation = new JLabel();
    cmbModelMutation = new DefaultComboBoxModel<ClassWrapper>();
    cmbMutation = new JComboBox<ClassWrapper>(cmbModelMutation);

    lblSelection = new JLabel();
    cmbModelSelection = new DefaultComboBoxModel<ClassWrapper>();
    cmbSelection = new JComboBox<ClassWrapper>(cmbModelSelection);

    lblFitness = new JLabel();
    cmbModelFitness = new DefaultComboBoxModel<ClassWrapper>();
    cmbFitness = new JComboBox<ClassWrapper>(cmbModelFitness);

    lblPathOutput = new JLabel();
    txtPathOutput = new JTextField();
    btnPathOutput = new JButton("...");

    lblName = new JLabel();
    txtName = new JTextField();

    lblAverage = new JLabel("");
    lblAverage.setHorizontalTextPosition(SwingConstants.LEFT);
    lblAverageTitle = new JLabel("Average: ");

    lblOffline = new JLabel("");
    lblOffline.setHorizontalTextPosition(SwingConstants.LEFT);
    lblOfflineTitle = new JLabel("Offline: ");

    lblOnline = new JLabel("");
    lblOnline.setHorizontalTextPosition(SwingConstants.LEFT);
    lblOnlineTitle = new JLabel("Online: ");

    lblElite = new JLabel("");
    lblElite.setHorizontalTextPosition(SwingConstants.LEFT);
    lblEliteTitle = new JLabel("Elite: ");

    average = new XYSeries("Average");
    offline = new XYSeries("Offline");
    online = new XYSeries("Online");
    elite = new XYSeries("Elite");

    dataset = new XYSeriesCollection();
    dataset.addSeries(average);
    dataset.addSeries(online);
    dataset.addSeries(elite);
    dataset.addSeries(offline);

    chart = ChartFactory.createXYLineChart("title", "xLabel", "yLabel", dataset, PlotOrientation.VERTICAL, true,
            true, false);
    chartPanel = new ChartPanel(chart);

    pnlCentral.add(lblLocale, "width 120, height 25");
    pnlCentral.add(cmbSelectLocale, "width 120, height 25, wrap");

    pnlCentral.add(lblLimLow, "width 120, height 25");
    pnlCentral.add(spiLow, "width 120, height 25");
    pnlCentral.add(lblIndividual, "width 80, height 25");
    pnlCentral.add(cmbIndividual, "growx, height 25, span 2, wrap");

    pnlCentral.add(lblLimUp, "width 120, height 25");
    pnlCentral.add(spiUp, "width 120, height 25");
    pnlCentral.add(lblCrossover, "width 80, height 25");
    pnlCentral.add(cmbCrossover, "growx, height 25, span 2, wrap");

    pnlCentral.add(lblChromosome, "width 120, height 25");
    pnlCentral.add(spiChromosome, "width 120, height 25");
    pnlCentral.add(lblMutation, "width 80, height 25");
    pnlCentral.add(cmbMutation, "growx, height 25, span 2, wrap");

    pnlCentral.add(lblPopulation, "width 120, height 25");
    pnlCentral.add(spiPopulation, "width 120, height 25");
    pnlCentral.add(lblSelection, "width 80, height 25");
    pnlCentral.add(cmbSelection, "growx, height 25, span 2");
    pnlCentral.add(lblAverageTitle, "width 70, height 25");
    pnlCentral.add(lblAverage, "width 200, height 25, wrap");

    pnlCentral.add(lblGenerations, "width 120, height 25");
    pnlCentral.add(spiGenerations, "width 120, height 25");
    pnlCentral.add(lblFitness, "width 80, height 25");
    pnlCentral.add(cmbFitness, "growx, height 25, span 2");
    pnlCentral.add(lblOnlineTitle, "growx, height 25");
    pnlCentral.add(lblOnline, "growx, height 25, wrap");

    pnlCentral.add(lblProbCrossover, "width 120, height 25");
    pnlCentral.add(txtProbCrossover, "width 120, height 25");
    pnlCentral.add(lblPathOutput, "width 80, height 25");
    pnlCentral.add(txtPathOutput, "width 280, height 25");
    pnlCentral.add(btnPathOutput, "width 20, height 25");
    pnlCentral.add(lblEliteTitle, "growx, height 25");
    pnlCentral.add(lblElite, "growx, height 25, wrap");

    pnlCentral.add(lblProbMutation, "width 120, height 25");
    pnlCentral.add(txtProbMutation, "width 120, height 25");
    pnlCentral.add(lblName, "width 80, height 25");
    pnlCentral.add(txtName, "growx, height 25, span 2");
    pnlCentral.add(lblOfflineTitle, "growx, height 25");
    pnlCentral.add(lblOffline, "growx, height 25, wrap");

    pnlCentral.add(chartPanel, "growx, span 7");

    // SOUTH
    pnlSouth = new JPanel();
    add(pnlSouth, BorderLayout.SOUTH);

    btnRun = new JButton();
    btnStop = new JButton();
    btnClose = new JButton();

    pnlSouth.add(btnRun);
    pnlSouth.add(btnStop);
    pnlSouth.add(btnClose);

    // ADD BUTTONS
    buttons.add(btnClose);
    buttons.add(btnStop);
    buttons.add(btnPathOutput);
    buttons.add(btnRun);
}

From source file:net.sf.jabref.gui.preftabs.AppearancePrefsTab.java

/**
 * Customization of appearance parameters.
 *
 * @param prefs a <code>JabRefPreferences</code> value
 *//*from   w w w.ja v a2s. co  m*/
public AppearancePrefsTab(JabRefPreferences prefs) {
    this.prefs = prefs;
    setLayout(new BorderLayout());

    // Font sizes:
    fontSize = new JTextField(5);

    // Row padding size:
    rowPadding = new JTextField(5);

    colorCodes = new JCheckBox(Localization.lang("Color codes for required and optional fields"));

    overrideFonts = new JCheckBox(Localization.lang("Override default font settings"));

    showGrid = new JCheckBox(Localization.lang("Show gridlines"));

    FormLayout layout = new FormLayout(
            "1dlu, 8dlu, left:pref, 4dlu, fill:pref, 4dlu, fill:60dlu, 4dlu, fill:pref", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);

    customLAF = new JCheckBox(Localization.lang("Use other look and feel"));
    // Only list L&F which are available
    List<String> lookAndFeels = LookAndFeel.getAvailableLookAndFeels();
    classNamesLAF = new JComboBox<>(lookAndFeels.toArray(new String[lookAndFeels.size()]));
    classNamesLAF.setEditable(true);
    final JComboBox<String> clName = classNamesLAF;
    customLAF.addChangeListener(e -> clName.setEnabled(((JCheckBox) e.getSource()).isSelected()));

    // only the default L&F shows the the OSX specific first dropdownmenu
    if (!OS.OS_X) {
        JPanel pan = new JPanel();
        builder.appendSeparator(Localization.lang("Look and feel"));
        JLabel lab = new JLabel(
                Localization.lang("Default look and feel") + ": " + UIManager.getSystemLookAndFeelClassName());
        builder.nextLine();
        builder.append(pan);
        builder.append(lab);
        builder.nextLine();
        builder.append(pan);
        builder.append(customLAF);
        builder.nextLine();
        builder.append(pan);
        JPanel pan2 = new JPanel();
        lab = new JLabel(Localization.lang("Class name") + ':');
        pan2.add(lab);
        pan2.add(classNamesLAF);
        builder.append(pan2);
        builder.nextLine();
        builder.append(pan);
        lab = new JLabel(Localization
                .lang("Note that you must specify the fully qualified class name for the look and feel,"));
        builder.append(lab);
        builder.nextLine();
        builder.append(pan);
        lab = new JLabel(Localization
                .lang("and the class must be available in your classpath next time you start JabRef."));
        builder.append(lab);
        builder.nextLine();
    }

    builder.leadingColumnOffset(2);
    JLabel lab;
    builder.appendSeparator(Localization.lang("General"));
    JPanel p1 = new JPanel();
    lab = new JLabel(Localization.lang("Menu and label font size") + ":");
    p1.add(lab);
    p1.add(fontSize);
    builder.append(p1);
    builder.nextLine();
    builder.append(overrideFonts);
    builder.nextLine();
    builder.appendSeparator(Localization.lang("Table appearance"));
    JPanel p2 = new JPanel();
    p2.add(new JLabel(Localization.lang("Table row height padding") + ":"));
    p2.add(rowPadding);
    builder.append(p2);
    builder.nextLine();
    builder.append(colorCodes);
    builder.nextLine();
    builder.append(showGrid);
    builder.nextLine();
    JButton fontButton = new JButton(Localization.lang("Set table font"));
    builder.append(fontButton);
    builder.nextLine();
    builder.appendSeparator(Localization.lang("Table and entry editor colors"));
    builder.append(colorPanel);

    JPanel upper = new JPanel();
    JPanel sort = new JPanel();
    JPanel namesp = new JPanel();
    JPanel iconCol = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    upper.setLayout(gbl);
    sort.setLayout(gbl);
    namesp.setLayout(gbl);
    iconCol.setLayout(gbl);

    overrideFonts.addActionListener(e -> fontSize.setEnabled(overrideFonts.isSelected()));

    fontButton.addActionListener(e -> new FontSelectorDialog(null, GUIGlobals.currentFont).getSelectedFont()
            .ifPresent(x -> usedFont = x));

    JPanel pan = builder.getPanel();
    pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(pan, BorderLayout.CENTER);
}

From source file:net.sourceforge.atunes.kernel.modules.state.RepositoryPanel.java

/**
 * Initializes panel//from w w  w  . j a v a2s. com
 */
public void initialize() {
    this.refreshTime = new JComboBox(new Integer[] { 0, 5, 10, 15, 30, 60 });
    this.commandBeforeAccessRepository = this.controlsBuilder.createTextField();
    this.commandBeforeAccessRepository.setColumns(20);
    this.commandAfterAccessRepository = this.controlsBuilder.createTextField();
    this.commandAfterAccessRepository.setColumns(20);
    this.repositoryFoldersList = this.lookAndFeelManager.getCurrentLookAndFeel().getList();
    this.repositoryFoldersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.addFolderButton = new JButton(I18nUtils.getString("ADD"));
    this.removeFolderButton = new JButton(I18nUtils.getString("REMOVE"));
    this.repositoryFoldersList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent event) {
            RepositoryPanel.this.removeFolderButton
                    .setEnabled(RepositoryPanel.this.repositoryFoldersList.getSelectedIndex() != -1);
        }
    });
    this.addFolderButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent arg0) {
            IFolderSelectorDialog dialog = RepositoryPanel.this.dialogFactory
                    .newDialog(IFolderSelectorDialog.class);
            dialog.setTitle(I18nUtils.getString("ADD_FOLDER_TO_REPOSITORY"));
            File folder = dialog.selectFolder(RepositoryPanel.this.osManager.getUserHome());
            if (folder != null) {
                RepositoryPanel.this.repositoryFolders.add(folder);
                RepositoryPanel.this.repositoryFoldersList
                        .setListData(RepositoryPanel.this.repositoryFolders.toArray());
            }
        }
    });
    this.removeFolderButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent event) {
            RepositoryPanel.this.repositoryFolders
                    .remove(RepositoryPanel.this.repositoryFoldersList.getSelectedIndex());
            RepositoryPanel.this.repositoryFoldersList
                    .setListData(RepositoryPanel.this.repositoryFolders.toArray());
        }
    });
    this.useRatingsStoredInTag = new JCheckBox(I18nUtils.getString("USE_RATINGS_STORED_IN_TAG"));
    setupPanel();
}