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:com.game.ui.views.PlayerEditor.java

public void doGui() {
    //        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new GridBagLayout());
    GridBagConstraints c1 = new GridBagConstraints();
    c1.fill = GridBagConstraints.NONE;
    c1.anchor = GridBagConstraints.WEST;
    c1.insets = new Insets(10, 5, 10, 5);
    c1.weightx = 0;/*from  w  ww.  j a v a  2 s .  com*/
    c1.weighty = 0;
    JLabel noteLbl = new JLabel("Pls select a value to choose a Player or you can create a new "
            + "Player entity below. Once selected a Player character, its' details will be available below");
    add(noteLbl, c1);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (GameCharacter character : GameBean.playerDetails) {
        model.addElement(((Player) character).getType());
    }
    c1.gridy = 1;
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(comboBox, c1);
    JPanel wrapperPanel = new JPanel(new GridLayout(1, 2, 10, 10));
    wrapperPanel.setBorder(LineBorder.createGrayLineBorder());
    leftPanel = new JPanel();
    leftPanel.setAlignmentX(0);
    leftPanel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel enemyDtlLbl = new JLabel("Enemy Character Details : ");
    enemyDtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    leftPanel.add(enemyDtlLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    leftPanel.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    leftPanel.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel imageLbl = new JLabel("Image Path : ");
    leftPanel.add(imageLbl, c);
    c.gridx = 1;
    JTextField image = new JTextField("");
    image.setColumns(20);
    leftPanel.add(image, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel healthLbl = new JLabel("Health Pts : ");
    leftPanel.add(healthLbl, c);
    c.gridx = 1;
    JTextField health = new JTextField("");
    health.setColumns(20);
    leftPanel.add(health, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    leftPanel.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    leftPanel.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    JLabel armoursPtsLbl = new JLabel("Armour Points : ");
    leftPanel.add(armoursPtsLbl, c);
    c.gridx = 1;
    JTextField armourPts = new JTextField("");
    armourPts.setColumns(20);
    leftPanel.add(armourPts, c);
    c.gridx = 0;
    c.gridy = 6;
    JLabel attackRngeLbl = new JLabel("Attack Range : ");
    leftPanel.add(attackRngeLbl, c);
    c.gridx = 1;
    JTextField attackRnge = new JTextField("");
    attackRnge.setColumns(20);
    leftPanel.add(attackRnge, c);
    c.gridx = 0;
    c.gridy = 7;
    JLabel movementLbl = new JLabel("Movement : ");
    leftPanel.add(movementLbl, c);
    c.gridx = 1;
    JTextField movement = new JTextField("");
    movement.setColumns(20);
    leftPanel.add(movement, c);
    c.gridx = 0;
    c.gridy = 8;
    JLabel typeLbl = new JLabel("Type : ");
    leftPanel.add(typeLbl, c);
    c.gridx = 1;
    JTextField typeTxt = new JTextField("");
    typeTxt.setColumns(20);
    leftPanel.add(typeTxt, c);
    c.gridx = 0;
    c.gridy = 9;
    JLabel weaponLbl = new JLabel("Equipped Weapon : ");
    leftPanel.add(weaponLbl, c);
    c.gridx = 1;
    DefaultComboBoxModel weapon = new DefaultComboBoxModel();
    for (Item item : GameBean.weaponDetails) {
        if (item instanceof Weapon) {
            weapon.addElement(((Weapon) item).getName());
        }
    }
    JComboBox weaponDrpDown = new JComboBox(weapon);
    weaponDrpDown.setSelectedIndex(-1);
    weaponDrpDown.setMaximumSize(new Dimension(100, 30));
    leftPanel.add(weaponDrpDown, c);
    c.gridx = 0;
    c.gridy = 10;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    leftPanel.add(submit, c);
    wrapperPanel.add(leftPanel);
    lvlPanel = new LevelPanel(true, null);
    wrapperPanel.add(lvlPanel);
    c1.gridy = 2;
    c1.fill = GridBagConstraints.BOTH;
    add(wrapperPanel, c1);
    c1.fill = GridBagConstraints.NONE;
    validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    c1.gridy = 3;
    add(validationMess, c1);
    c1.weightx = 1;
    c1.fill = GridBagConstraints.BOTH;
    c1.weighty = 1;
    c1.gridy = 4;
    add(new JPanel(), c1);
}

From source file:ComboBoxDemo2.java

public ComboBoxDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z",
            "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    currentPattern = patternExamples[0];

    // Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setEditable(true);//from w  ww .  j  av  a 2 s  .  c  o  m
    patternList.addActionListener(this);

    // Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); // ==
                                                                          // LEFT
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

    JPanel resultPanel = new JPanel(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    add(patternPanel);
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(resultPanel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();
}

From source file:net.nosleep.superanalyzer.analysis.views.PlayCountView.java

private void createPanel() {
    _comboBox = new JComboBox(_analysis.getComboBoxItems());
    _comboBox.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            refreshDataset();/*  w w w . j a v a2s. c o  m*/
        }
    });

    _dataset = new XYBarDataset(collection, 0.9);

    createChart();
    _chartPanel = new ChartPanel(_chart);
    _chartPanel.setMouseWheelEnabled(true);

    refreshDataset();
}

From source file:net.nosleep.superanalyzer.analysis.views.GrowthView.java

private void createPanel() {

    _comboBox = new JComboBox(_analysis.getComboBoxItems());
    _comboBox.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            refreshDataset();/*from  w  w  w.jav a2  s.  c om*/
        }
    });

    _dataset = new TimeSeriesCollection();

    createChart();
    _chartPanel = new ChartPanel(_chart);
    _chartPanel.setMouseWheelEnabled(true);

    refreshDataset();

    _comboBox = new JComboBox(_analysis.getComboBoxItems());
    _comboBox.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            refreshDataset();
        }
    });
}

From source file:net.nosleep.superanalyzer.analysis.views.YearView.java

private void createPanel() {
    _comboBox = new JComboBox(_analysis.getComboBoxItems());
    _comboBox.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            refreshDataset();// w  w  w . j av a 2  s .co m
        }
    });

    _dataset = new XYSeriesCollection();

    createChart();
    _chartPanel = new ChartPanel(_chart);
    _chartPanel.setMouseWheelEnabled(true);

    refreshDataset();
}

From source file:org.kineticsystem.commons.data.demo.panels.AggregationChartPane.java

/**
 * Constructor.//from   w  ww .  j  a v  a 2 s  .  co m
 * @param source This is the source list being modified ate the same time
 *     by many threads.
 */
public AggregationChartPane(ActiveList<RandomContact> source) {

    // Define aggregators.

    GroupAggregator[] aggregators = new GroupAggregator[] { new ContactsPerContinentAggr(),
            new AvgAgePerContinentAggr(), new MaxAgePerContinentAggr(), new MinAgePerContinentAggr() };

    // Aggregator selector.

    DefaultComboBoxModel groupComboModel = new DefaultComboBoxModel(aggregators);
    final JComboBox groupCombo = new JComboBox(groupComboModel);
    groupCombo.setSelectedIndex(1);
    groupCombo.setToolTipText("Select an aggregation function.");

    // Create the dataset.

    dataset = new DefaultCategoryDataset();
    List<Country> countries = RandomContactGenerator.getCountries();
    Set<String> continents = new TreeSet<String>();

    for (Country country : countries) {
        continents.add(country.getContinent());
    }

    for (String continent : continents) {
        dataset.setValue(0, continent, "");
    }

    // Define the aggregated list.

    groups = new GroupMapping<RandomContact>(source);
    groups.setAggregator(aggregators[0]);
    groups.getTarget().addActiveListListener(this);

    // Create the chart.

    JFreeChart chart = ChartFactory.createBarChart("", "Continent", groups.getAggregator().toString(), dataset,
            PlotOrientation.VERTICAL, true, // legend?
            true, // tooltips?
            false // URLs?
    );
    final ValueAxis axis = chart.getCategoryPlot().getRangeAxis();
    axis.setAutoRange(true);
    axis.setRange(0, 250);

    ChartPanel chartPanel = new ChartPanel(chart);

    // Create the selector.

    ActionListener groupComboListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            GroupAggregator aggr = (GroupAggregator) cb.getSelectedItem();
            groups.setAggregator(aggr);
            axis.setLabel(aggr.toString());
        }
    };
    groupCombo.addActionListener(groupComboListener);

    // Layout the GUI.

    Cell cell = new Cell();

    TetrisLayout groupTableLayout = new TetrisLayout(2, 1);
    groupTableLayout.setRowWeight(0, 0);
    groupTableLayout.setRowWeight(1, 100);

    setLayout(groupTableLayout);
    add(groupCombo, cell);
    add(chartPanel, cell);
}

From source file:SoundApplet.java

public void init() {
    String[] fileTypes = { auFile, aiffFile, midiFile, rmfFile, wavFile };
    formats = new JComboBox(fileTypes);
    formats.setSelectedIndex(0);//from w  w  w.j av  a2 s. c o  m
    chosenFile = (String) formats.getSelectedItem();
    formats.addItemListener(this);

    playButton = new JButton("Play");
    playButton.addActionListener(this);

    loopButton = new JButton("Loop");
    loopButton.addActionListener(this);

    stopButton = new JButton("Stop");
    stopButton.addActionListener(this);
    stopButton.setEnabled(false);

    JPanel controlPanel = new JPanel();
    controlPanel.add(formats);
    controlPanel.add(playButton);
    controlPanel.add(loopButton);
    controlPanel.add(stopButton);
    getContentPane().add(controlPanel);

    startLoadingSounds();
}

From source file:com.willwinder.universalgcodesender.uielements.panels.ControllerProcessorSettingsPanel.java

public ControllerProcessorSettingsPanel(Settings settings, IChanged changer,
        Map<String, ConfigTuple> configFiles) {
    super(settings, changer);
    this.configFiles = configFiles;

    this.controllerConfigs = new JComboBox(configFiles.keySet().toArray());
    this.customRemoverTable = initCustomRemoverTable(new JTable());
    super.updateComponents();

    controllerConfigs.addActionListener(e -> {
        if (!updatingCombo)
            super.updateComponents();
    });/*from ww w.j  a v  a  2  s.  c  om*/
    add.addActionListener(e -> this.addNewPatternRemover());
    remove.addActionListener(e -> this.removeSelectedPatternRemover());
}

From source file:EditableComboBox.java

public EditableComboBox() {
    // Build a mapping from book titles to their entries
    for (int i = 0; i < books.length; i++) {
        bookMap.put(books[i].getTitle(), books[i]);
    }//from  ww w  . j  a  va 2s .c o m

    setLayout(new BorderLayout());

    JComboBox bookCombo = new JComboBox(books);
    bookCombo.setEditable(true);
    bookCombo.setEditor(new ComboBoxEditorExample(bookMap, books[0]));
    bookCombo.setMaximumRowCount(4);
    bookCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!");
        }
    });
    bookCombo.setActionCommand("Hello");
    add(bookCombo, BorderLayout.CENTER);
}

From source file:com.mirth.connect.manager.HeapSizeDialog.java

public HeapSizeDialog(String heapSize) {
    super(PlatformUI.MANAGER_DIALOG, true);

    managerController = ManagerController.getInstance();
    getRootPane().registerKeyboardAction(new ActionListener() {
        @Override//from  w  w w. jav a  2 s  .  c  o  m
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);

    setResizable(false);
    setBackground(Color.white);
    setTitle("Web Start Settings");
    getContentPane().setBackground(Color.white);

    initComponents();

    this.heapSize = StringUtils.isEmpty(heapSize) ? "512m" : heapSize;

    String heapSizeOption = HeapSize.toDisplayName(heapSize);
    if (StringUtils.isBlank(heapSizeOption)) {
        heapSizeOption = this.heapSize;
    }

    // Add any non-default properties to the model
    String property = (String) managerController.getServerProperties()
            .getProperty(ManagerConstants.ADMINISTRATOR_MAX_HEAP_SIZE);
    if (!heapSizeComboboxModel.contains(property)
            && !heapSizeComboboxModel.contains(HeapSize.toDisplayName(property))) {
        heapSizeComboboxModel.add(formatCustomProperty(property));
    }

    // Resort list by sizes
    List<String> mbList = new ArrayList<String>();
    List<String> gbList = new ArrayList<String>();
    for (String size : heapSizeComboboxModel) {
        if (size.contains("M")) {
            mbList.add(size);
        } else {
            gbList.add(size);
        }
    }

    Collections.sort(mbList);
    Collections.sort(gbList);
    mbList.addAll(gbList);

    heapSizeComboBox = new JComboBox(mbList.toArray());
    heapSizeComboBox.getModel().setSelectedItem(formatCustomProperty(heapSizeOption));

    initLayout();
    pack();
    setLocationRelativeTo(PlatformUI.MANAGER_DIALOG);
    setVisible(true);
}