1个回答
展开全部
下面这个程序或许会对你有帮助,
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;
public class 处理树鼠标事件 extends JApplet {
public 处理树鼠标事件() {
JTree tree = new JTree();
getContentPane().add(new JScrollPane(tree));
tree.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
String s = null;
JTree t = (JTree)e.getSource();
int row = t.getRowForLocation(e.getX(), e.getY());
if(e.getClickCount() == 2)
s = "double click in row " + row;
else
s = "single click in row " + row;
if(row != -1) {
TreePath path = t.getPathForRow(row);
TreeNode node = (TreeNode)
path.getLastPathComponent();
s += ", node = " + node.toString();
}
showStatus(s);
}
});
}
}
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;
public class 处理树鼠标事件 extends JApplet {
public 处理树鼠标事件() {
JTree tree = new JTree();
getContentPane().add(new JScrollPane(tree));
tree.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
String s = null;
JTree t = (JTree)e.getSource();
int row = t.getRowForLocation(e.getX(), e.getY());
if(e.getClickCount() == 2)
s = "double click in row " + row;
else
s = "single click in row " + row;
if(row != -1) {
TreePath path = t.getPathForRow(row);
TreeNode node = (TreeNode)
path.getLastPathComponent();
s += ", node = " + node.toString();
}
showStatus(s);
}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询