This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
|
swing:combo_box [2016/05/26 14:29] gthanos |
swing:combo_box [2018/04/13 09:22] gthanos [Νon-editable combo box] |
||
|---|---|---|---|
| Line 20: | Line 20: | ||
| Παρακάτω δίνονται δύο παραδείγματα από το site της Oracle, ένα για // | Παρακάτω δίνονται δύο παραδείγματα από το site της Oracle, ένα για // | ||
| - | ==== Νon-editable combo box ==== | + | ===== Νon-editable combo box ===== |
| <code java ComboBoxDemo.java> | <code java ComboBoxDemo.java> | ||
| - | |||
| import java.awt.*; | import java.awt.*; | ||
| import java.awt.event.*; | import java.awt.event.*; | ||
| Line 36: | Line 35: | ||
| | | ||
| */ | */ | ||
| + | @SuppressWarnings({" | ||
| public class ComboBoxDemo extends JPanel | public class ComboBoxDemo extends JPanel | ||
| implements ActionListener { | implements ActionListener { | ||
| Line 47: | Line 47: | ||
| //Create the combo box, select the item at index 4. | //Create the combo box, select the item at index 4. | ||
| //Indices start at 0, so 4 specifies the pig. | //Indices start at 0, so 4 specifies the pig. | ||
| - | JComboBox petList = new JComboBox(petStrings); | + | JComboBox< |
| petList.setSelectedIndex(4); | petList.setSelectedIndex(4); | ||
| petList.addActionListener(this); | petList.addActionListener(this); | ||
| Line 71: | Line 71: | ||
| /** Listens to the combo box. */ | /** Listens to the combo box. */ | ||
| public void actionPerformed(ActionEvent e) { | public void actionPerformed(ActionEvent e) { | ||
| - | JComboBox cb = (JComboBox)e.getSource(); | + | JComboBox< |
| String petName = (String)cb.getSelectedItem(); | String petName = (String)cb.getSelectedItem(); | ||
| updateLabel(petName); | updateLabel(petName); | ||
| Line 77: | Line 77: | ||
| protected void updateLabel(String name) { | protected void updateLabel(String name) { | ||
| - | ImageIcon icon = createImageIcon(" | + | ImageIcon icon = createImageIcon(name + " |
| picture.setIcon(icon); | picture.setIcon(icon); | ||
| picture.setToolTipText(" | picture.setToolTipText(" | ||
| Line 132: | Line 132: | ||
| Το παραπάνω πρόγραμμα προϋποθέτει τις παρακάτω εικόνες {{: | Το παραπάνω πρόγραμμα προϋποθέτει τις παρακάτω εικόνες {{: | ||
| - | ==== Εditable combo box ==== | + | ===== Εditable combo box ===== |
| <code java ComboBoxDemo2.java> | <code java ComboBoxDemo2.java> | ||
| Line 264: | Line 264: | ||
| + | | Προηγούμενο: | ||