import java.awt.BorderLayout;
import java.awt.Panel;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
public class HalloWelt extends JPanel {
public static final String REVISION = "$LastChangedRevision$"; /** * @param args */
public static void main(String[] args) {
JFrame fenster = new JFrame("Mouse");
fenster.setVisible(true);
fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String listData[] = { "Eintrag1", "Eintrag2", "Eintrag3", };
final JList liste = new JList(listData);
JScrollPane pane = new JScrollPane(liste);
final JTextField field = new JTextField(30);
field.setEditable(true);
final JTextField field1 = new JTextField(30);
field1.setEditable(true);
final JTextField field2 = new JTextField(30);
field2.setEditable(true);
liste.addMouseMotionListener(new MouseAdapter() {
String lastSelected = "";
@Override
public void mouseMoved(MouseEvent me) {
Point p = new Point(me.getX(),me.getY());
String value = (String) liste.getModel().getElementAt(liste.locationToIndex(p));
if(!value.equals(lastSelected)) {
lastSelected = value;
field.setText(value);
}
}
@Override
public void mouseClicked(MouseEvent mew)
{
liste.remove(liste.getSelectedIndex());
}
});
JPanel panel = new JPanel();
JPanel panelCenter = new JPanel();
panel.setLayout(new BorderLayout());
panelCenter.setLayout(new BoxLayout(panelCenter,BoxLayout.Y_AXIS));
panelCenter.add(field);
panelCenter.add(field1);
panelCenter.add(field2);
panel.add(panelCenter,BorderLayout.CENTER);
panel.add(pane,BorderLayout.WEST);
fenster.add(panel);
}}