User Tools

Site Tools


swing:combo_box

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
swing:combo_box [2018/03/27 17:09]
gthanos [Νon-editable combo box]
swing:combo_box [2018/04/13 09:22]
gthanos [Νon-editable combo box]
Line 20: Line 20:
 Παρακάτω δίνονται δύο παραδείγματα από το site της Oracle, ένα για //non-editable// combo box και ένα για //editable// combo box. Παρακάτω δίνονται δύο παραδείγματα από το site της Oracle, ένα για //non-editable// combo box και ένα για //editable// combo box.
  
-==== Ν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:
    images/Pig.gif    images/Pig.gif
  */  */
 +@SuppressWarnings({"serial", "unchecked"})
 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<String> petList = new JComboBox<>(petStrings);
     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> cb = (JComboBox<String>)e.getSource();
     String petName = (String)cb.getSelectedItem();     String petName = (String)cb.getSelectedItem();
     updateLabel(petName);     updateLabel(petName);
Line 132: Line 132:
 Το παραπάνω πρόγραμμα προϋποθέτει τις παρακάτω εικόνες {{:swing:animals.zip|}}. Το παραπάνω πρόγραμμα προϋποθέτει τις παρακάτω εικόνες {{:swing:animals.zip|}}.
  
-==== Εditable combo box ====+===== Εditable combo box =====
  
 <code java ComboBoxDemo2.java> <code java ComboBoxDemo2.java>
Line 264: Line 264:
  
  
 +| Προηγούμενο: [[:swing:lists | Λίστες - Η κλάση JList ]] | [[:toc | Περιεχόμενα ]] | Επόμενο: [[:swing:panels | Η κλάση JPanel ]] |
  
swing/combo_box.txt · Last modified: 2018/04/13 08:27 (external edit)