List of usage examples for javax.swing JComboBox addActionListener
public void addActionListener(ActionListener l)
ActionListener
. From source file:Main.java
public Main() { setPreferredSize(new Dimension(320, 240)); add(odometer);//from w w w .j av a 2s. c o m JComboBox colorBox = new JComboBox(new String[] { "a", "b" }); colorBox.addActionListener(e -> { tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), "my full new title"); }); this.add(colorBox); timer = new Timer(250, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { km += random.nextInt(100); odometer.setText(df.format(km)); } }); timer.start(); }
From source file:Main.java
public Main() { Vector model = new Vector(); model.addElement(new Item(1, "A")); model.addElement(new Item(2, "B")); model.addElement(new Item(3, "C")); model.addElement(new Item(4, "D")); JComboBox comboBox = new JComboBox(model); comboBox.addActionListener(this); comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); getContentPane().add(comboBox, BorderLayout.NORTH); comboBox = new JComboBox(model); comboBox.setRenderer(new ItemRenderer()); comboBox.addActionListener(this); getContentPane().add(comboBox, BorderLayout.SOUTH); }
From source file:Main.java
public Main() { String[] comboTypes = { "Numbers", "Alphabets", "Symbols" }; JComboBox<String> comboTypesList = new JComboBox<>(comboTypes); comboTypesList.setSelectedIndex(2);//from ww w . j av a2 s . co m comboTypesList.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JComboBox jcmbType = (JComboBox) e.getSource(); String cmbType = (String) jcmbType.getSelectedItem(); System.out.println(cmbType); } }); setLayout(new BorderLayout()); add(comboTypesList, BorderLayout.NORTH); }
From source file:Main.java
public Main() { Vector model = new Vector(); model.addElement(new Item(1, "A")); model.addElement(new Item(2, "B")); model.addElement(new Item(4, "C")); model.addElement(new Item(3, "D")); JComboBox comboBox = new JComboBox(model); comboBox.setRenderer(new ItemRenderer()); comboBox.addActionListener(this); getContentPane().add(comboBox, BorderLayout.SOUTH); }
From source file:Main.java
public JPanel getContent() { String[] ids = { "north", "west", "south", "east" }; Boolean[] values = { Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE }; CheckComboStore[] stores = new CheckComboStore[ids.length]; for (int j = 0; j < ids.length; j++) stores[j] = new CheckComboStore(ids[j], values[j]); JComboBox combo = new JComboBox(stores); combo.setRenderer(new CheckComboRenderer()); combo.addActionListener(this); JPanel panel = new JPanel(); panel.add(combo);//from w w w. java2s . c o m return panel; }
From source file:Main.java
public Main() { setPreferredSize(new Dimension(320, 240)); setBackground(hue.getColor());/*from w w w. ja v a 2s . com*/ JComboBox colorBox = new JComboBox(); for (Hue h : Hue.values()) { colorBox.addItem(h); } colorBox.addActionListener(e -> { Hue h = (Hue) colorBox.getSelectedItem(); Main.this.setBackground(h.getColor()); }); this.add(colorBox); }
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);/*from w w w .ja va 2 s . c o m*/ 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:Main.java
private JComboBox createComboBox(final Map<Integer, Student> map) { final JComboBox cbox = new JComboBox(); for (Integer id : map.keySet()) { cbox.addItem(id);/*from ww w.java2s . c om*/ } cbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Integer id = (Integer) cbox.getSelectedItem(); System.out.println(map.get(id)); } }); return cbox; }
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 . ja v a 2 s.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: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 .ja v a2s . 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)); }