import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Test_Event extends JFrame {
public Test_Event() {
super("JTable und Listener");
initGUI();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
}
public void initGUI() {
JPanel panelForTabbedPane = new JPanel();
JTabbedPane tabPane = new JTabbedPane();
String[] spalten_Namen = { "Spalte 1", "Spalte 2" };
String[][] spalten_Inhalt = { { "1", "4" }, { "2", "5" }, { "3", "6" } };
JTable table = new JTable(spalten_Inhalt, spalten_Namen);
JScrollPane jsp = new JScrollPane();
jsp.setViewportView(table);
DefaultTableModel model = new DefaultTableModel(spalten_Inhalt,
spalten_Namen);
table.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
System.out
.println("Ich befinde mich mit der Maus über der JTable!");
}
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
});
panelForTabbedPane.add(tabPane);
tabPane.addTab("Tab 1", jsp);
add(panelForTabbedPane);
}
public static void main(String[] args) {
new Test_Event();
}
}