rendered paste bodyimport java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class gui
extends JFrame
implements
ListSelectionListener
{
// Instance attributes used in this example
private JPanel topPanel;
private JList listbox;
private Vector listData;
private JScrollPane scrollPane;
// Constructor of main frame
public gui()
{
setTitle( "Hello world" );
setSize( 300, 100 );
setBackground( Color.gray );
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
listData = new Vector();
listbox = new JList( listData );
listbox.addListSelectionListener( this );
scrollPane = new JScrollPane();
scrollPane.getViewport().add( listbox );
topPanel.add( scrollPane, BorderLayout.CENTER );
CreateDataEntryPanel();
setVisible(true);
}
public void CreateDataEntryPanel()
{
JPanel dataPanel = new JPanel();
dataPanel.setLayout( new BorderLayout() );
topPanel.add( dataPanel, BorderLayout.SOUTH );
}
public void valueChanged( ListSelectionEvent event )
{
if( event.getSource() == listbox
&& !event.getValueIsAdjusting() )
{
// Get the current selection and place it in the
// edit field
String stringValue = (String)listbox.getSelectedValue();
//if( stringValue != null )
// dataField.setText( stringValue );
}
}
public void add(String s){
listData.addElement(s);
listbox.setListData( listData );
scrollPane.revalidate();
scrollPane.repaint();
}
}