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:ToolBarExample.java

public ToolBarExample() {
    menuBar = new JMenuBar();

    // Create a set of actions to use in both the menu and toolbar
    DemoAction leftJustifyAction = new DemoAction("Left", new ImageIcon("1.gif"), "Left justify text", 'L');
    DemoAction rightJustifyAction = new DemoAction("Right", new ImageIcon("2.gif"), "Right justify text", 'R');
    DemoAction centerJustifyAction = new DemoAction("Center", new ImageIcon("3.gif"), "Center justify text",
            'M');
    DemoAction fullJustifyAction = new DemoAction("Full", new ImageIcon("4.gif"), "Full justify text", 'F');

    JMenu formatMenu = new JMenu("Justify");
    formatMenu.add(leftJustifyAction);/*  w  w  w.  j  a va  2 s.  c  om*/
    formatMenu.add(rightJustifyAction);
    formatMenu.add(centerJustifyAction);
    formatMenu.add(fullJustifyAction);

    menuBar.add(formatMenu);

    toolBar = new JToolBar("Formatting");
    toolBar.add(leftJustifyAction);
    toolBar.add(rightJustifyAction);
    toolBar.add(centerJustifyAction);
    toolBar.add(fullJustifyAction);

    toolBar.addSeparator();
    JLabel label = new JLabel("Font");
    toolBar.add(label);

    toolBar.addSeparator();
    JComboBox combo = new JComboBox(fonts);
    combo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                pane.getStyledDocument().insertString(0,
                        "Font [" + ((JComboBox) e.getSource()).getSelectedItem() + "] chosen!\n", null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    toolBar.add(combo);

    //  Disable one of the Actions
    fullJustifyAction.setEnabled(false);
}

From source file:CompositeTest.java

public CompositeTestFrame() {
    setTitle("CompositeTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    canvas = new CompositeComponent();
    add(canvas, BorderLayout.CENTER);

    ruleCombo = new JComboBox(new Object[] { new Rule("CLEAR", "  ", "  "), new Rule("SRC", " S", " S"),
            new Rule("DST", "  ", "DD"), new Rule("SRC_OVER", " S", "DS"), new Rule("DST_OVER", " S", "DD"),
            new Rule("SRC_IN", "  ", " S"), new Rule("SRC_OUT", " S", "  "), new Rule("DST_IN", "  ", " D"),
            new Rule("DST_OUT", "  ", "D "), new Rule("SRC_ATOP", "  ", "DS"), new Rule("DST_ATOP", " S", " D"),
            new Rule("XOR", " S", "D "), });
    ruleCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Rule r = (Rule) ruleCombo.getSelectedItem();
            canvas.setRule(r.getValue());
            explanation.setText(r.getExplanation());
        }/*w w  w.j a  v  a 2s . c  o m*/
    });

    alphaSlider = new JSlider(0, 100, 75);
    alphaSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
            canvas.setAlpha(alphaSlider.getValue());
        }
    });
    JPanel panel = new JPanel();
    panel.add(ruleCombo);
    panel.add(new JLabel("Alpha"));
    panel.add(alphaSlider);
    add(panel, BorderLayout.NORTH);

    explanation = new JTextField();
    add(explanation, BorderLayout.SOUTH);

    canvas.setAlpha(alphaSlider.getValue());
    Rule r = (Rule) ruleCombo.getSelectedItem();
    canvas.setRule(r.getValue());
    explanation.setText(r.getExplanation());
}

From source file:net.nosleep.superanalyzer.analysis.views.EncodingKindView.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. j  a  v a  2 s .c o  m
        }
    });

    _dataset = new DefaultPieDataset();

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

    refreshDataset();
}

From source file:ComboBoxDemo.java

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

    String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };

    //Create the combo box, select the item at index 4.
    //Indices start at 0, so 4 specifies the pig.
    JComboBox petList = new JComboBox(petStrings);
    petList.setSelectedIndex(4);/*  w  w w. j  a v a  2s .c  o m*/
    petList.addActionListener(this);

    //Set up the picture.
    picture = new JLabel();
    picture.setFont(picture.getFont().deriveFont(Font.ITALIC));
    picture.setHorizontalAlignment(JLabel.CENTER);
    updateLabel(petStrings[petList.getSelectedIndex()]);
    picture.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));

    //The preferred size is hard-coded to be the width of the
    //widest image and the height of the tallest image + the border.
    //A real program would compute this.
    picture.setPreferredSize(new Dimension(177, 122 + 10));

    //Lay out the demo.
    add(petList, BorderLayout.PAGE_START);
    add(picture, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:com.game.ui.views.CharachterEditorPanel.java

public void doGui() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel noteLbl = new JLabel("Pls select a value to choose an enemy or you can create a new "
            + "Enemy entity below. Once selected an Enemy character, its' details will be available below");
    noteLbl.setAlignmentX(0);/*from  w w  w .  j a v a2s.c  om*/
    //        noteLbl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (GameCharacter character : GameBean.enemyDetails) {
        System.out.println(character.getName());
        model.addElement(character.getName());
    }
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setAlignmentX(0);
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(Box.createVerticalStrut(10));
    add(comboBox);
    add(Box.createVerticalStrut(10));
    JPanel panel1 = new JPanel();
    panel1.setAlignmentX(0);
    panel1.setBorder(LineBorder.createGrayLineBorder());
    panel1.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));
    panel1.add(enemyDtlLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    panel1.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    panel1.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel imageLbl = new JLabel("Image Path : ");
    panel1.add(imageLbl, c);
    c.gridx = 1;
    JTextField image = new JTextField("");
    image.setColumns(20);
    panel1.add(image, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel healthLbl = new JLabel("Health Pts : ");
    panel1.add(healthLbl, c);
    c.gridx = 1;
    JTextField health = new JTextField("");
    health.setColumns(20);
    panel1.add(health, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    panel1.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    panel1.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    JLabel armoursPtsLbl = new JLabel("Armour Points : ");
    panel1.add(armoursPtsLbl, c);
    c.gridx = 1;
    JTextField armourPts = new JTextField("");
    armourPts.setColumns(20);
    panel1.add(armourPts, c);
    c.gridx = 0;
    c.gridy = 6;
    JLabel attackRngeLbl = new JLabel("Attack Range : ");
    panel1.add(attackRngeLbl, c);
    c.gridx = 1;
    JTextField attackRnge = new JTextField("");
    attackRnge.setColumns(20);
    panel1.add(attackRnge, c);
    c.gridx = 0;
    c.gridy = 7;
    JLabel movementLbl = new JLabel("Movement : ");
    panel1.add(movementLbl, c);
    c.gridx = 1;
    JTextField movement = new JTextField("");
    movement.setColumns(20);
    panel1.add(movement, c);
    c.gridx = 0;
    c.gridy = 8;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    panel1.add(submit, c);
    add(panel1);
    c.gridx = 0;
    c.gridy = 9;
    JLabel validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    add(validationMess, c);
    add(Box.createVerticalGlue());
}

From source file:jchrest.gui.VisualSearchPane.java

public VisualSearchPane(Chrest model, Scenes scenes) {
    super();//from   ww  w.  j ava2s  .  c  om

    _model = model;
    _scenes = scenes;
    //TODO: fix this when perceiver functionality working correctly.
    //_model.getPerceiver().setScene (_scenes.get (0));
    _model.setClocks(0);
    _sceneDisplay = new SceneDisplay(_scenes.get(0));
    _domainSelector = new JComboBox(new String[] { "Generic", "Chess" });
    _domainSelector.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            int index = _domainSelector.getSelectedIndex();
            if (index == 0) {
                _model.setDomain(new GenericDomain(_model, null, 3));
            } else { // if (index == 1) 
                //TODO: fix this when perceiver functionality working correctly.
                //_model.setDomain (new ChessDomain (_model));
            }
        }
    });

    JTabbedPane jtb = new JTabbedPane();
    jtb.addTab("Train", trainPanel());
    jtb.addTab("Recall", recallPanel());
    jtb.addTab("Log", logPanel());
    jtb.addTab("Analyse", analysePanel());

    setLayout(new BorderLayout());
    add(jtb);
}

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

private void createComponent(Predicate projectFilter) {
    projectsCombobox = new JComboBox(projectList(projectFilter));
    new ComboBoxAutoCompletion(projectsCombobox);
    model = new DefaultListModel();
    list = new JList(model);
    list.setPreferredSize(new Dimension(150, 150));
    projectsCombobox.addItemListener(new ItemListener() {
        @Override/*  www .  java  2s.  c  o m*/
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                updateList(e.getItem());
            }
        }
    });

    setLayout(new BorderLayout());
    add(projectsCombobox, BorderLayout.NORTH);
    add(new JScrollPane(list), BorderLayout.CENTER);
}

From source file:components.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);//www  .j a v a  2 s.  co  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:com.emental.mindraider.ui.dialogs.DownloadModelJDialog.java

/**
 * Constructor.//from  ww w  . jav  a  2 s .c om
 * 
 * @param union
 *            made union of models.
 */
public DownloadModelJDialog(boolean union) {
    super(Messages.getString("DownloadModelJDialog.title"));

    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 5));

    p.add(new JLabel(Messages.getString("DownloadModelJDialog.url")));

    String[] knowUris = new String[] { "http://", "http://wymiwyg.org/", "http://www.osar.ch",
            "http://wymiwyg.org/.rdf?appendLang=en&till=50", "http://www.osar.ch/.rdf?appendLang=de&till=50" };
    modelUrlCombo = new JComboBox(knowUris);
    modelUrlCombo.setEditable(true);
    modelUrlCombo.addKeyListener(new KeyListener() {

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

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    p.add(modelUrlCombo);

    JButton uploadButton = new JButton(Messages.getString("DownloadModelJDialog.download"));
    uploadButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            upload();
        }
    });
    p.add(uploadButton);

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

        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    p.add(cancelButton);

    getContentPane().add(p, BorderLayout.CENTER);

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

From source file:net.nosleep.superanalyzer.analysis.views.TimeView.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 ww .j  av  a2  s.  c o m
        }
    });

    _dataset = new DefaultCategoryDataset();

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

    refreshDataset();
}