swing控件的一些操作

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].

posted @ 2013-06-09 11:09  rhino  阅读(385)  评论(0编辑  收藏  举报