मैंने समाधान का प्रयास किया, आप भी इसका उपयोग करते हैं।
कोड प्रस्तुत मेरी राय के बाद वहां इष्टतम नहीं है: - यह सभी नोड्स के लिए tree.expandPath कहता है, बजाय यह केवल गहरी गैर पत्र-गांठ (पत्र-गांठ पर expandPath बुला कोई प्रभाव नहीं है के लिए बुलाने की, JDK देखें)
यहाँ एक सही संस्करण जो तेजी से होना चाहिए:
// If expand is true, expands all nodes in the tree.
// Otherwise, collapses all nodes in the tree.
public void expandAll(JTree tree, boolean expand) {
TreeNode root = (TreeNode)tree.getModel().getRoot();
if (root!=null) {
// Traverse tree from root
expandAll(tree, new TreePath(root), expand);
}
}
/**
* @return Whether an expandPath was called for the last node in the parent path
*/
private boolean expandAll(JTree tree, TreePath parent, boolean expand) {
// Traverse children
TreeNode node = (TreeNode)parent.getLastPathComponent();
if (node.getChildCount() > 0) {
boolean childExpandCalled = false;
for (Enumeration e=node.children(); e.hasMoreElements();) {
TreeNode n = (TreeNode)e.nextElement();
TreePath path = parent.pathByAddingChild(n);
childExpandCalled = expandAll(tree, path, expand) || childExpandCalled; // the OR order is important here, don't let childExpand first. func calls will be optimized out !
}
if (!childExpandCalled) { // only if one of the children hasn't called already expand
// Expansion or collapse must be done bottom-up, BUT only for non-leaf nodes
if (expand) {
tree.expandPath(parent);
} else {
tree.collapsePath(parent);
}
}
return true;
} else {
return false;
}
}
आप 100,000 नोड्स के साथ पूरी तरह से जेटीरी का विस्तार क्यों करना चाहते हैं? नोड्स का केवल एक अंश स्क्रीन पर फिट होगा वैसे भी ऐसा करने में क्या फायदा है? – Adamski
उपयोग केस हमारे डेटास्ट्रक्चर में सभी बिल सामग्री में एक हिस्से का उपयोग दिखा रहा है।यह सैद्धांतिक रूप से डेटा की इतनी बड़ी मात्रा में नेतृत्व कर सकता है। अभी मैं यह पता लगाने की कोशिश कर रहा हूं कि जेटी तकनीकी रूप से क्या संभव है (विशेष रूप से डेल्फी/सी ++ घटक वर्चुअल ट्री व्यू के मुकाबले) – hagt