Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JTree collapsePath

Empfohlene Antworten

Hallo zusammen,

ich hab ein kleines Problem. Ich möchte auf Knopfdruck in meinem JTree alle Nodes der 2. Ebene unter dem Wurzelkoten wieder zusammenklappen. Ich hab das mit folgendem Code versucht:


Enumeration objServerNodes = m_nodeRoot.children();
while (objServerNodes.hasMoreElements())
{
CElkTreeNode objServerNode = (CElkTreeNode) objServerNodes.nextElement();

Enumeration objProjectNodes = objServerNode.children();

while (objProjectNodes.hasMoreElements())
{
CElkTreeNode objProjectNode = (CElkTreeNode) objProjectNodes.nextElement();

CElkProject objAttachedProject = (CElkProject)objProjectNode.getAttachedObject();
if (CElkObjectHelper.isTypeOf(objProjectNode, "de.emediaoffice.elk.topologie.CElkProject"))
{
TreePath objPath = new TreePath(objProjectNode);
m_treeDocuments.collapsePath(objPath);
}

}
}

m_treeDocuments.validate();

[/PHP]

Macht aber gar nichts! Habs auch durchdebuggt, collapsePath wird auch aufgerufen, Hat mir einer von euch einen Rat oder Tipp?

hi,

lt. java-almanac funktioniert es folgendermassen:

    // 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();


        // Traverse tree from root

        expandAll(tree, new TreePath(root), expand);

    }

    private void expandAll(JTree tree, TreePath parent, boolean expand) {

        // Traverse children

        TreeNode node = (TreeNode)parent.getLastPathComponent();

        if (node.getChildCount() >= 0) {

            for (Enumeration e=node.children(); e.hasMoreElements(); ) {

                TreeNode n = (TreeNode)e.nextElement();

                TreePath path = parent.pathByAddingChild(n);

                expandAll(tree, path, expand);

            }

        }


        // Expansion or collapse must be done bottom-up

        if (expand) {

            tree.expandPath(parent);

        } else {

            tree.collapsePath(parent);

        }

    }

müsstest halt noch auf knotenebene 2 einschränken beim zusammenfalten...

hth...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.