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

import java.util.Vector;

// Beispiel mit zwei Listen
// Listen durchs Arrays

public class Liste06a extends JFrame {


  Vector items = new Vector();
  JList jlist;

  //Frame konstruieren
  public Liste06a() {
     JButton bnOk;
     JButton bnDelete;

     JPanel panel;
     JScrollPane scroll;

    setSize(420, 320);
    setTitle("JList Liste06");

    panel = new JPanel();
    panel.setLayout ( null );

    bnOk = new JButton("Ok");  // Label erzeugen
    panel.add(bnOk);
    bnOk.setBounds(50, 250, 150, 20); // x/y   width height


    bnDelete = new JButton("Delete");  // Label erzeugen
    panel.add(bnDelete);
    bnDelete.setBounds(250, 250, 150, 20); // x/y   width height

    bnDelete.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        bn2_delete();
      }
    });


    for (int i=0; i<20; i++) {
      items.add( Integer.toHexString(i+1)+" Auswahl" );
    }

    jlist = new JList(items);
    jlist.setBounds(20, 20, 350, 200); // x/y   width height
       // Generiere eine Scrollbox, Inhalt Liste
    scroll = new JScrollPane(jlist);
    scroll.setBounds(20, 20, 350, 200); // x/y   width height
    panel.add(scroll);

    this.getContentPane().add(panel, BorderLayout.CENTER);

    jlist.setFont( new Font("Arial", Font.BOLD,18)  );
    bnOk.setFont( new Font("Arial", Font.BOLD,18)  );
    bnDelete.setFont( new Font("Arial", Font.BOLD,18)  );

  } // create


  public void bn2_delete() {
    int i;
    //items.removeAllElements();
    int n = items.size();
    for (i=0; i<n; i++) {
       items.remove( n-i-1 );
       jlist.updateUI();
    }
    /*
    if ( items.size()>5) {
      items.remove(3);
      liste.paintImmediately(0,0,400,410);
    }
    */
  }

  //Überschreiben, damit das Programm bei Herunterfahren des Systems beendet werden kann
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if(e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }


  public static void main(String[] args) {
    Liste06a frame = new Liste06a();
    frame.setVisible(true);
  }


}
