MouseAdapterを使用してJTreeノードのダブルクリックを確認しています。私は、選択されたノードのレベルに応じて、いくつかの異なるアクションが必要です。どのようにしてノードのレベルを確認できますか?ここでは、リスナーのためのコードは次のとおりです。JTree:選択レベルを確認
private MouseAdapter getMouseAdapter(JTree jtree) {
final JTree tree = jtree;
return new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
if (selPath != null) {
if (e.getClickCount() == 2) {
String selectedNode = selPath.getLastPathComponent().toString();
// >>>>> check on which level of the tree this node is
}
}
}};
}
JavaDocsの最新バージョンにリンクすることをお勧めします。私はあなたの答えをJ2SE 7を指すように編集しました。最新のドキュメントへのリンクを得るためのヒントについては、[ポイント2の利点](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7090875)を参照してください。 。 –
その働き。ありがとう! – Giannis