FileDocCategorySizeDatePackage
CustomComboBoxDemo.javaAPI DocExample2440Tue Dec 12 18:59:22 GMT 2000None

CustomComboBoxDemo

public class CustomComboBoxDemo extends JPanel

Fields Summary
ImageIcon[]
images
Constructors Summary
public CustomComboBoxDemo()

        //Load the pet images
        String[] petStrings = {"Bird", "Cat", "Dog", "Rabbit", "Pig"};
        images = new ImageIcon[petStrings.length];
        for (int i = 0; i < petStrings.length; i++) {
            images[i] = new ImageIcon("images/" + petStrings[i] + ".gif");
            images[i].setDescription(petStrings[i]);
        }

        // Create the combo box
        JComboBox petList = new JComboBox(images);
        ComboBoxRenderer renderer= new ComboBoxRenderer();
        renderer.setPreferredSize(new Dimension(200, 130));
        petList.setRenderer(renderer);
        petList.setMaximumRowCount(3);

        // Layout the demo
        setLayout(new BorderLayout());
        add(petList, BorderLayout.NORTH);
        setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
    
Methods Summary
public static voidmain(java.lang.String[] s)

        JFrame frame = new JFrame("CustomComboBoxDemo");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });
 
        frame.getContentPane().add(new CustomComboBoxDemo(),
                                   BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);