我是Swing的一位新的,非常綠色的用戶。我設法使用java.sun教程中的示例創建表類,並且我設法動態地將數據加載到它中。我希望能夠通過顯示一個對話框來對點擊行做出反應。如何添加將識別所選行號的事件處理程序?如何將mouseClicked事件添加到擺動表中?
主要功能代碼:
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
MainWindow window = new MainWindow();
window.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
createAndShowGUI();
//...
}
}
}
}
和
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Data Table");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up data of the content pane.
TableClass mainTable = new TableClass(fh.getColNames(), fh.getTableContent());
mainTable.setOpaque(true);
frame.setContentPane(mainTable);
//Display the window.
frame.pack();
frame.setVisible(true);
}
謝謝
重新格式化的代碼;如果不正確請回復。 – trashgod 2010-05-07 17:44:32