Lists and Combo Boxes

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Lister {
public static void main(String[] args) {
JFrame f = new JFrame(“Lister v1.0”);
f.setSize(200, 200);
f.setLocation(200, 200);
f.addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent we) { System.exit(0); }

// create a combo box
// Made By Ajinkya Choube
String [] items = { “uno”, “due”, “tre”, “quattro”, “cinque”,
“sei”, “sette”, “otto”, “nove”, “deici”,
“undici”, “dodici” };
JComboBox comboBox = new JComboBox(items);

// create a list with the same data model
final JList list = new JList(comboBox.getModel( ));

// create a button; when it’s pressed, print out
// the selection in the list
JButton button = new JButton(“Per favore”);
button.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ae) {
Object[] selection = list.getSelectedValues( );
for (int i = 0; i < selection.length; i++)

// put the controls the content pane
Container c = f.getContentPane( );
JPanel comboPanel = new JPanel( );
c.add(comboPanel, BorderLayout.NORTH);
c.add(new JScrollPane(list), BorderLayout.CENTER);
c.add(button, BorderLayout.SOUTH);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s