1,不显示JTree父子之间节点的连线:

    tree.putClientProperty("JTree.lineStyle", "None");

2,如何让JTree的添加节点可见:

    //主要用到的方法    
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
        DefaultTreeModel model = new DefaultTreeModel(root);
        JTree tree = new JTree(model);
        tree.putClientProperty("JTree.lineStyle", "None");
        DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(
                "helloKitty");

        TreePath path = tree.getSelectionPath();
        DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) path
                .getLastPathComponent();
        model.insertNodeInto(treeNode, selectNode, selectNode.getChildCount());
        TreeNode[] nodes = model.getPathToRoot(treeNode);
        TreePath path2 = new TreePath(nodes);
        tree.makeVisible(path2);
        tree.scrollPathToVisible(path2);

 3,JTable中的rowAtPoint(Point point)方法,可以返回某个点在哪一行,做拖拽的时候,定位比较有用。

int javax.swing.JTable.rowAtPoint(Point point)

Returns the index of the row that point lies in, or -1 if the result is not in the range [0, getRowCount()-1].

相关文章:

  • 2022-12-23
  • 2021-11-20
  • 2021-11-22
  • 2022-01-23
  • 2021-09-14
  • 2021-10-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2021-08-16
  • 2021-05-29
相关资源
相似解决方案