Can I put JLabel array in JComboBox?
Here is the code. It runs but does not display the labels. Why?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Combo implements ActionListener{
JComboBox comboBox;
JLabel i= new JLabel();
JLabel[] items = new JLabel[4];
public static void main(String[] args) {
JFrame f = new JFrame("Interest Rate");
Combo c=new Combo();
f.setSize(300, 200);
f.setLocation(200, 200);
Container pane = f.getContentPane();
c.items[0] = new JLabel("5.25");
c.items[1] = new JLabel("5.5");
c.items[2] = new JLabel("5.75");
c.items[3] = new JLabel("6.0");
c.create();
c.comboBox.setEditable(true);
BorderLayout brd = new BorderLayout();
pane.setLayout(brd);
pane.add(c.comboBox,BorderLayout.NORTH);
pane.add(c.items[0],BorderLayout.CENTER);
pane.add(c.i, BorderLayout.SOUTH);
f.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
Object selection = comboBox.getSelectedItem();
i.setText("User has selected interest rate " + selection + "%");
}
private void create(){
comboBox = new JComboBox(items);
comboBox.addActionListener(this);
}}