//Titel: fuer die 3. Hausaufgabe, Programmierung 2 //Version: 1,0 //Copyright: Copyright (c) 2013 //Autor: M. Wilhelm //Organisation: HS-Harz //Beschreibung: GridBagLayout import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.util.Vector; public class Aufgabe04_JList extends JFrame implements ActionListener { public static final long serialVersionUID=1; JMenuItem mnAktion = new JMenuItem("Aktion"); // notwendige globale GUI-Elemente JButton bn1 = new JButton("JList Aktion1"); JTextField input = new JTextField(); Vector liste = new Vector(); JList jlist1; public Aufgabe04_JList() { setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setGUI(); setMenus(); } private void setGUI() { setSize(700, 270); setTitle("Beispiel JList"); this.getContentPane().setLayout( new GridBagLayout() ); jlist1= new JList(liste); // Verknuepfung JList mit Vector JLabel lInput = new JLabel("Eingabe"); this.getContentPane().add(lInput , new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(20,20,20,20), 0, 0)); this.getContentPane().add( input, new GridBagConstraints( 1, 0, 1, 1, 100.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(20,0,20,0), 0, 0)); JLabel lJList = new JLabel("JList"); this.getContentPane().add(lJList, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(20,20,20,20), 0, 0)); this.getContentPane().add( new JScrollPane(jlist1), new GridBagConstraints( 1, 1, 1, 1, 100.0, 100.0 ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(20,0,20,0), 0, 0)); setFont( this.getContentPane() ); jlist1.setFont( new Font("Arial", Font.BOLD,18) ); // wg. JScrollPane } // setGUI private void setFont(Container parent) { //System.out.println("parent: "+parent+" "+parent.getComponentCount() ); for (int i=0; i