List of usage examples for javax.swing JComboBox JComboBox
public JComboBox(Vector<E> items)
JComboBox
that contains the elements in the specified Vector. From source file:com.game.ui.views.WeaponEditorPanel.java
public void doGui() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JLabel noteLbl = new JLabel( "<html><div style='width : 500px;'>Pls select a value to choose an Weapon or you can create a new " + "Weapon entity below. Once selected a weapon, its' details will be available below</div></html>"); noteLbl.setAlignmentX(0);/*from www .j ava 2 s. co m*/ add(noteLbl); DefaultComboBoxModel model = new DefaultComboBoxModel(); for (Item item : GameBean.weaponDetails) { if (item instanceof Weapon) { model.addElement(((Weapon) item).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(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 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 weaponDtsLbl = new JLabel("Weapon Details : "); weaponDtsLbl.setFont(new Font("Times New Roman", Font.BOLD, 15)); panel1.add(weaponDtsLbl, 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 weaponTypeLbl = new JLabel("Weapon Type : "); panel1.add(weaponTypeLbl, c); c.gridx = 1; JComboBox weaponType = new JComboBox(Configuration.weaponTypes); weaponType.setSelectedIndex(0); weaponType.setPreferredSize(name.getPreferredSize()); System.out.println(name.getPreferredSize()); panel1.add(weaponType, c); c.gridx = 0; c.gridy = 3; JLabel attackRangeLbl = new JLabel("Attack Range : "); panel1.add(attackRangeLbl, c); c.gridx = 1; JTextField attackRange = new JTextField(""); attackRange.setColumns(20); panel1.add(attackRange, 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; c.gridwidth = 2; JButton submit = new JButton("Save"); submit.addActionListener(this); submit.setActionCommand("button"); panel1.add(submit, c); c.gridx = 0; c.gridy = 6; c.gridwidth = 2; c.weighty = 0; c.weightx = 1; validationMess = new JLabel("Pls enter all the fields or pls choose a weapon from the drop down"); validationMess.setForeground(Color.red); validationMess.setVisible(false); panel1.add(validationMess, c); // c.fill = GridBagConstraints.BOTH; // c.gridy = 7; // c.weightx = 1; // c.weighty = 1; // panel1.add(new JLabel(""), c); panel1.setBorder(LineBorder.createGrayLineBorder()); add(panel1); add(Box.createVerticalGlue()); }
From source file:InternalFrameListenerDemo.java
public InternalFrameListenerDemo() { setTitle("Animated InternalFrameListener"); m_count = m_tencount = 0;/*from w ww . j a v a 2s .c o m*/ JPanel innerListenerPanel = new JPanel(new GridLayout(7, 1)); JPanel listenerPanel = new JPanel(new BorderLayout()); m_ifEventCanvas = new IFEventCanvas(); m_lOpened = new JLabel("internalFrameOpened"); m_lClosing = new JLabel("internalFrameClosing"); m_lClosed = new JLabel("internalFrameClosed"); m_lIconified = new JLabel("internalFrameIconified"); m_lDeiconified = new JLabel("internalFrameDeiconified"); m_lActivated = new JLabel("internalFrameActivated"); m_lDeactivated = new JLabel("internalFrameDeactivated"); innerListenerPanel.add(m_lOpened); innerListenerPanel.add(m_lClosing); innerListenerPanel.add(m_lClosed); innerListenerPanel.add(m_lIconified); innerListenerPanel.add(m_lDeiconified); innerListenerPanel.add(m_lActivated); innerListenerPanel.add(m_lDeactivated); listenerPanel.add("Center", m_ifEventCanvas); listenerPanel.add("West", innerListenerPanel); listenerPanel.setOpaque(true); listenerPanel.setBackground(Color.white); m_desktop = new JDesktopPane(); m_desktop.setBorder(new SoftBevelBorder(BevelBorder.LOWERED)); m_newFrame = new JButton("New Frame"); m_newFrame.addActionListener(this); m_infos = UIManager.getInstalledLookAndFeels(); String[] LAFNames = new String[m_infos.length]; for (int i = 0; i < m_infos.length; i++) { LAFNames[i] = m_infos[i].getName(); } m_UIBox = new JComboBox(LAFNames); m_UIBox.addActionListener(this); JPanel topPanel = new JPanel(true); topPanel.setLayout(new FlowLayout()); topPanel.setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED), new CompoundBorder(new EmptyBorder(2, 2, 2, 2), new SoftBevelBorder(BevelBorder.RAISED)))); getContentPane().setLayout(new BorderLayout()); getContentPane().add("North", topPanel); getContentPane().add("Center", m_desktop); getContentPane().add("South", listenerPanel); ((JPanel) getContentPane()).setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED), new CompoundBorder(new EmptyBorder(1, 1, 1, 1), new SoftBevelBorder(BevelBorder.RAISED)))); topPanel.add(m_newFrame); topPanel.add(new JLabel("Look & Feel:", SwingConstants.RIGHT)); topPanel.add(m_UIBox); setSize(645, 500); Dimension dim = getToolkit().getScreenSize(); setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2); setVisible(true); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(l); m_eventTimer = new Timer(1000, this); m_eventTimer.setRepeats(true); m_eventTimer.start(); }
From source file:de.fhg.igd.iva.explorer.main.CompareViewPanel.java
public CompareViewPanel(Table<KnownColormap, ColormapQuality, Double> info) { this.table = info; setBorder(new EmptyBorder(5, 5, 5, 5)); setLayout(new BorderLayout()); JPanel statsPanel = new JPanel(new BorderLayout()); // statsLabel = new JLabel(); // statsLabel.setBorder(BorderFactory.createTitledBorder("Statistics")); // statsPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); statsBars = new JPanel(new GridBagLayout()); statsPanel.add(statsBars, BorderLayout.NORTH); // statsPanel.add(statsLabel, BorderLayout.SOUTH); add(statsPanel, BorderLayout.SOUTH); cmView = new ColormapPanel(new ConstantColormap(), 256); cmView.setBorder(new EmptyBorder(5, 0, 5, 0)); add(cmView, BorderLayout.CENTER); mapsCombo = new JComboBox<KnownColormap>(table.rowKeySet().toArray(new KnownColormap[0])); mapsCombo.addActionListener(new ActionListener() { @Override// www .ja v a 2s . c om public void actionPerformed(ActionEvent e) { updateSelection(); } }); mapsCombo.setSelectedIndex(0); add(mapsCombo, BorderLayout.NORTH); }
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 ww w. java 2s . c om 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:hermes.browser.dialog.ClasspathIdCellEdtitor.java
public Component getTableCellEditorComponent(JTable table, Object value, boolean arg2, int arg3, int arg4) { try {/*from w w w . j a v a2s . c o m*/ if (tableToCombo.containsKey(table)) { return (Component) tableToCombo.get(table); } else { final Vector items = new Vector(); for (Iterator iter = HermesBrowser.getBrowser().getConfig().getClasspathGroup().iterator(); iter .hasNext();) { ClasspathGroupConfig config = (ClasspathGroupConfig) iter.next(); items.add(config.getId()); } items.add("System"); final JComboBox combo = new JComboBox(items); combo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { selection = (String) combo.getSelectedItem(); } }); if (value != null) { combo.setSelectedItem(value); } log.debug("value=" + value); tableToCombo.put(table, combo); return combo; } } catch (HermesException e) { log.error(e.getMessage(), e); } return table; }
From source file:events.ListSelectionDemo.java
public ListSelectionDemo() { super(new BorderLayout()); String[] listData = { "one", "two", "three", "four", "five", "six", "seven" }; String[] columnNames = { "French", "Spanish", "Italian" }; list = new JList(listData); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); JScrollPane listPane = new JScrollPane(list); JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2);/*from w ww. ja v a 2 s. c o m*/ 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(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); listContainer.setBorder(BorderFactory.createTitledBorder("List")); listContainer.add(listPane); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); //topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(100, 50)); topHalf.setPreferredSize(new Dimension(100, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); 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:DropDemo.java
private JPanel createList() { DefaultListModel listModel = new DefaultListModel(); for (int i = 0; i < 10; i++) { listModel.addElement("List Item " + i); }/*from w w w. j a v a 2s . c o m*/ list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(list); scrollPane.setPreferredSize(new Dimension(400, 100)); list.setDragEnabled(true); list.setTransferHandler(new ListTransferHandler()); dropCombo = new JComboBox(new String[] { "USE_SELECTION", "ON", "INSERT", "ON_OR_INSERT" }); dropCombo.addActionListener(this); JPanel dropPanel = new JPanel(); dropPanel.add(new JLabel("List Drop Mode:")); dropPanel.add(dropCombo); JPanel panel = new JPanel(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); panel.add(dropPanel, BorderLayout.SOUTH); panel.setBorder(BorderFactory.createTitledBorder("List")); return panel; }
From source file:fuel.gui.stats.MotorStatsPanel.java
public MotorStatsPanel(Database database) throws SQLException { this.database = database; controller = new Controller(); JPanel container = new JPanel(new BorderLayout()); //container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); JPanel motorSelectionPanel = new JPanel(); motorSelectionPanel.setLayout(new BoxLayout(motorSelectionPanel, BoxLayout.X_AXIS)); motorSpecsPanel = new JPanel(new GridLayout(2, 3)); motorSpecsPanel.setBorder(BorderFactory.createTitledBorder("Specs")); graphContainer = new JPanel(); graphContainer.setLayout(new BoxLayout(graphContainer, BoxLayout.Y_AXIS)); JComboBox motorSelector = new JComboBox(database.getMotorcycles().toArray()); motorSelector.setActionCommand("SELECTMOTOR"); motorSelector.addActionListener(controller); motorSelectionPanel.add(motorSelector); //motorSelector.setSelectedIndex(0); motorSelectionPanel.add(motorSpecsPanel); refreshMotorSpecs((Motorcycle) motorSelector.getSelectedItem()); container.add(motorSelectionPanel, BorderLayout.NORTH); JScrollPane scroll = new JScrollPane(graphContainer); scroll.getHorizontalScrollBar().setUnitIncrement(10); scroll.getVerticalScrollBar().setUnitIncrement(10); container.add(scroll, BorderLayout.CENTER); refreshGraphs((Motorcycle) motorSelector.getSelectedItem()); setLayout(new BorderLayout()); add(container);//from ww w .ja v a 2 s.com setVisible(true); }
From source file:ListIt.java
public ListIt() { JFrame f = new JFrame(); final PartsListModel pcm = new PartsListModel(); ListCellRenderer lcr = new MyLabelRenderer(); JList jl = new JList(pcm); jl.setCellRenderer(lcr);/*w ww . j av a 2s . c o m*/ ListSelectionModel lsm = jl.getSelectionModel(); lsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jl.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { String element[] = (String[]) pcm.getElementAt(e.getFirstIndex()); System.out.println(element[0] + " : " + element[1] + " : " + element[2]); } } }); JScrollPane jsp = new JScrollPane(jl); JComboBox jc = new JComboBox(pcm); jc.setRenderer(lcr); JButton jb = new JButton("Add Merchandise"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pcm.addElement(partsList[(int) (Math.random() * partsList.length)]); } }); Container c = f.getContentPane(); c.add(jsp, BorderLayout.NORTH); c.add(jc, BorderLayout.CENTER); c.add(jb, BorderLayout.SOUTH); f.setSize(250, 250); f.show(); }
From source file:com.emental.mindraider.ui.dialogs.SearchConceptAnnotation.java
/** * Constructor.//from w ww . j a v a 2s . c om */ public SearchConceptAnnotation(AbstractTextAnnotationRenderer renderer) { super("Search Annotation"); this.renderer = renderer; JPanel dialogPanel = new JPanel(); dialogPanel.setBorder(new EmptyBorder(5, 10, 0, 10)); dialogPanel.setLayout(new BorderLayout()); JPanel contentAndButtons = new JPanel(new GridLayout(2, 1)); JPanel contentPanel = new JPanel(new BorderLayout()); // 1a. // TODO add help like in eclipse contentPanel.add(new JLabel(Messages.getString("FtsJDialog.searchString")), BorderLayout.NORTH); // 1b. searchCombo = new JComboBox(history.toArray()); searchCombo.setSelectedItem(""); searchCombo.setPreferredSize(new Dimension(200, 18)); searchCombo.setEditable(true); searchCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if ("comboBoxEdited".equals(e.getActionCommand())) { search(); } } }); contentPanel.add(searchCombo, BorderLayout.SOUTH); contentAndButtons.add(contentPanel); // 2. JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 5)); JButton searchButton = new JButton(Messages.getString("FtsJDialog.searchButton")); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { search(); } }); p.add(searchButton); JButton cancelButton = new JButton(Messages.getString("FtsJDialog.cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); p.add(cancelButton); contentAndButtons.add(p); dialogPanel.add(contentAndButtons, BorderLayout.CENTER); getContentPane().add(dialogPanel, BorderLayout.CENTER); // show pack(); Gfx.centerAndShowWindow(this); }