For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.
import org.dotuseful.ui.tree; public class ABSortTreeNode extends SortedTreeNode implements Comparable public int compareTo(Object o) { MutableTreeNode node = (MutableTreeNode)o; return ((Comparable)getUserObject()).compareTo(node.getUserObject()); } }
/** * @param root of tree * @return sorted elements alphabetically */ public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) { for (int i = 0; i < root.getChildCount(); i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) root .getChildAt(i); String nt = node.getUserObject().toString(); for (int j=0; j<i; j++) { DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) root .getChildAt(j); String np = prevNode.getUserObject().toString(); if (nt.compareToIgnoreCase(np)<0) { root.insert(node, j); root.insert(prevNode, i); } } if (node.getChildCount() > 0) { node = sortTree(node); } } return root; }
public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) { { for (int i =0; i<root.getChildCount()-1; i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i); String nt = node.getUserObject().toString(); for (int j=i+1;j<=root.getChildCount()-1;j++) { DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) root.getChildAt(j); String np = prevNode.getUserObject().toString(); System.out.println(nt+" "+np); if (nt.compareToIgnoreCase(np)>0) { root.insert(node, j); root.insert(prevNode, i); } } if (node.getChildCount() > 0) { node = sortTree(node); } } return root; } }
public void jTreeSortingBegin() { dn = (DefaultMutableTreeNode)treeModel.getRoot(); treeModel.reload(); dn = sortTree(dn); treeModel.reload(dn); }
addObject(jTextField1.getText()); jTreeSortingBegin();
root.insert(prevNode, i);
break;