JTree remove expand/collapse cross button...??

Hi all,
I have forbidden tree collapsing (by default it is fully expanded),
and I want to remove expand/collapse cross buttons that actually are used to expand/collapse tree nodes.
Is it possible and can anyone give me advice how i can do this.
Thanks in advance.

I tried extending the BasicTreeUI to return nulls for the collapsed and exapnded icons as shown in the code below. For the most part, it works great! However, one can still expand/collapse the tree by clicking on the point where the vertical and horizontal lines connect.
I guess some one else will take over from here.
import java.awt.BorderLayout;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.WindowConstants;
import javax.swing.plaf.basic.BasicTreeUI;
import javax.swing.tree.DefaultMutableTreeNode;
public class Temp extends JFrame {
     private JTree tree = null;
     public Temp() {
          super("Test");
          setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          initComponents();
          pack();
          setVisible(true);
     private void initComponents() {
          DefaultMutableTreeNode rootNode =
               new DefaultMutableTreeNode("User Preferences", true);
          DefaultMutableTreeNode connectionSettingsNode =
               new DefaultMutableTreeNode("Connection Settings", true);
          DefaultMutableTreeNode sslNode =
               new DefaultMutableTreeNode("SSL", false);
          DefaultMutableTreeNode firewallNode =
               new DefaultMutableTreeNode("Firewall", false);
          DefaultMutableTreeNode securityNode =
               new DefaultMutableTreeNode("Security", true);
          DefaultMutableTreeNode serverCertificatesNode =
               new DefaultMutableTreeNode("Server Certificates", false);
          DefaultMutableTreeNode clientCertificatesNode =
               new DefaultMutableTreeNode("Client Certificates", false);
          connectionSettingsNode.add(sslNode);
          connectionSettingsNode.add(firewallNode);
          securityNode.add(serverCertificatesNode);
          securityNode.add(clientCertificatesNode);
          rootNode.add(connectionSettingsNode);
          rootNode.add(securityNode);
          tree = new JTree(rootNode);
          JScrollPane scroller = new JScrollPane(tree);
          getContentPane().add(scroller, BorderLayout.CENTER);
          tree.setUI(new MyTreeUI());
          //tree.setShowsRootHandles(false);
     public static void main(String args []) {
          new Temp();
     class MyTreeUI extends BasicTreeUI {
          public Icon getCollapsedIcon() {
               return null;
          public Icon getExpandedIcon() {
               return null;
}Sai Pullabhotla

Similar Messages

  • Expand /Collapse push button

    Hi Guys,
    I have problem with expand/collapse push button in my selection-screen. In the older version 4.6c icon is displaying  good where as in the ECC6  the instead of symbol, the icon id is displaying.
        How to display the symbol ?
    Regards,
    Narasimha

    Hi Vijay,
        The Icon Id  @k1@ is for expand and the @k2@ is for the collapse
    In the selection-screen instaed of symbol these ID's are displaying.
    Regards,
    Narasimha

  • How do I remove expand / collapse icon for JTree empty folders

    Hi
    I am using a JTree as a file system browser. I use DefaultMutableTreeNode nodes.
    I have a problem with empty folders.
    Empty folders show the expand / collapse icon, leading the user to believe there are sub-directories. When the user double-clicks the folder, the expand / collapse icon goes away. This is a "haha-gotcha" glitch that I really don't want my users to have to continually deal with.
    So, how might I get my JTree to not show the expand / collapse icon for empty folders?
    Thanks
    Wayne

    Maybe I can use the FileSystemView isTraversable(File f) method in my TreeCellRenderer class to check if anything is in the directory.
    But I still need to know how to disable the expand / collapse icon for such a node.

  • JTree without expand/collapse icons

    I want to be able to hide or change the expand/collapse icon of a specific node, not the entire Jtree.
    Is there any way to do that?
    Tahnx

    I want to be able to hide or change the expand/collapse icon of a specific node, not the entire Jtree.
    Is there any way to do that?
    Tahnx

  • Problem with JTree while expanding/collapsing a node

    Hi,
    I'm using a JTree for displaying the file system.
    Here, i want that whenever a node get expanded,
    it should show the latest files/directories under that node.
    Now, what i'm doing is, getting all the files/dir's using files.listFiles(),
    under that node and then creating a new node and adding it to parent (all in expand() method).
    But, now the problem is, while doing this whenever the parent node get expanded its adding all the latest files/dirs into the previous instance
    resulting the same file/dir is displaying twice,thrice.. and so on, as that node is expanded and collapsed.
    i tried removeAllChildren() in collapse() method but then that node is notexpanding at all .
    Can anybody help me please...
    i got stuck b'coz of this only.
    Thanks...

    Now what i'm doing is every time expand() get called,
    i'm comparing all the children of that node in the
    current instance with all the children present in the
    file system (because there is a possibility that some
    file/dir may be added or deleted)
    is this the right wy or not?it certainly is not wrong, but as usual, there is more than 1 way to implement this...
    b'coz right now i'm getting all the files/dirs that
    are newly added but facing some problem if somebody
    deletes a file/dir.
    i'm still trying to get the solutionthen you should not just compare all the children of the node with the files/dirs but also the other way round. compare the files/dirs with the children to determine if the file/dir still exists and if not remove the node.
    or you could check if the file which a node represents exists and if not remove the node.
    thomas

  • DHTML Tree Expand-Collapse ALL buttons

    Hi
    I am using at DHTML Tree (in APEX 3.0.1) as a menu. I am wondering if it is possible to add buttons (or link) to the region which a user can click to expand all or collapse all nodes in the tree.
    I don not want the tree to be expanded or collapsed all the time (as when using the Tree List template)
    Thanks

    Anyone?

  • TOC Missing +/- (expand/collapse) boxes

    Never seen this before, but my TOC is suddenly missing the
    +/- expand/collapse topic buttons. Anyone know what the problem is
    here? TOC is set to binary.
    Here are the params from the HHC file:
    <object type="text/site properties">
    <param name="FrameName" value="_blank">
    <param name="WindowName" value="FreeDOM">
    <param name="SiteType" value="toc">
    <param name="Window Styles" value="0x800002">
    <param name="ExWindow Styles" value="0x100">
    </object>
    Any change to params?
    Thanks,
    John

    Hi John
    Is this for .CHM or WebHelp? If it's WebHelp, you need some
    images. You may obtain some by
    clicking
    here.
    If it's for compiled .CHM, you need to look at the Single
    Source Layout properties. Click the Advanced... button, then the
    TOC Styles tab. Click to enable Lines from Root, then you will be
    able to choose Plus/Minus Squares.
    Hope this helps a smidge... Rick

  • How do I remove the "TOC" btn in the playbar WITHOUT removing the TOC "Expand/Collapse" icon?

    I am working in CP7 on a project with a Table of Contents that is set to 'Overlay'. The client has requested that I remove the "TOC" button in the playbar, without removing the TOC "Expand/Collapse" icon, so that the user can still hide/reveal the TOC when necessary. The only control I can find is the "Show TOC" checkbox under Project > Table of Contents. However, un-checking this option removes both the "TOC" button AND the "Expand/Collapse" icons. Is it possible to remove just the "TOC" button in the playbar?

    If you are using SWF output you can always edit the playbar in Flash and remove it.
    If HTML5 you can edit the JavaScript out put to remove the button from the playbar.

  • JTree with XML content expand/collapse problem

    Hello all,
    I'm having this very weird problem with a JTree I use to display the contents of an XML file. I use the DOM parser (and not JDOM since I want the application to run as an applet as well, and don't want to have any external libraries for the user to download) and have a custom TreeModel and TreeNode implementations to wrap the DOM nodes so that they are displayed by the JTree.
    I have also added a popup menu in the tree, for the user to be able to expand/collapse all nodes under the selected one (i.e. a recursive method).
    When expandAll is run, everything works fine and the children of the selected node are expanded (and their children and so on).
    However, after the expansion when I run the collapseAll function, even though the selected node collapses, when I re-expand it (manually not by expandAll) all of it's children are still fully open! Even if I collapse sub-elements of the node manually and then collapse this node and re-expand it, it "forgets" the state of it's children and shows them fully expanded.
    In other words once I use expandAll no matter what I do, the children of this node will be expanded (once I close it and re-open it).
    Also after running expandAll the behaviour(!) of the expanded nodes change: i have tree.setToggleClickCount(1); but on the expanded nodes I need to double-click to collapse them.
    I believe the problem is related to my implementations of TreeModel and TreeNode but after many-many hours of trying to figure out what's happening I'm desperate... Please help!
    Here's my code:
    public class XMLTreeNode implements TreeNode 
         //This class wraps a DOM node
        org.w3c.dom.Node domNode;
        protected boolean allowChildren;
        protected Vector children;
        //compressed view (#text).
         private static boolean compress = true;   
        // An array of names for DOM node-types
        // (Array indexes = nodeType() values.)
        static final String[] typeName = {
            "none",
            "Element",
            "Attr",
            "Text",
            "CDATA",
            "EntityRef",
            "Entity",
            "ProcInstr",
            "Comment",
            "Document",
            "DocType",
            "DocFragment",
            "Notation",
        static final int ELEMENT_TYPE =   1;
        static final int ATTR_TYPE =      2;
        static final int TEXT_TYPE =      3;
        static final int CDATA_TYPE =     4;
        static final int ENTITYREF_TYPE = 5;
        static final int ENTITY_TYPE =    6;
        static final int PROCINSTR_TYPE = 7;
        static final int COMMENT_TYPE =   8;
        static final int DOCUMENT_TYPE =  9;
        static final int DOCTYPE_TYPE =  10;
        static final int DOCFRAG_TYPE =  11;
        static final int NOTATION_TYPE = 12;
        // The list of elements to display in the tree
       static String[] treeElementNames = {
            "node",
      // Construct an Adapter node from a DOM node
      public XMLTreeNode(org.w3c.dom.Node node) {
        domNode = node;
      public String toString(){
           if (domNode.hasAttributes()){
                return domNode.getAttributes().getNamedItem("label").getNodeValue();
           }else return domNode.getNodeName();      
      public boolean isLeaf(){ 
           return (this.getChildCount()==0);
      boolean treeElement(String elementName) {
          for (int i=0; i<treeElementNames.length; i++) {
            if ( elementName.equals(treeElementNames)) return true;
    return false;
    public int getChildCount() {
         if (!compress) {   
    return domNode.getChildNodes().getLength();
    int count = 0;
    for (int i=0; i<domNode.getChildNodes().getLength(); i++) {
    org.w3c.dom.Node node = domNode.getChildNodes().item(i);
    if (node.getNodeType() == ELEMENT_TYPE
    && treeElement( node.getNodeName() ))
    // Note:
    // Have to check for proper type.
    // The DOCTYPE element also has the right name
    ++count;
    return count;
    public boolean getAllowsChildren() {
         // TODO Auto-generated method stub
         return true;
    public Enumeration children() {
         // TODO Auto-generated method stub
         return null;
    public TreeNode getParent() {
         // TODO Auto-generated method stub
         return null;
    public TreeNode getChildAt(int searchIndex) {
    org.w3c.dom.Node node =
    domNode.getChildNodes().item(searchIndex);
    if (compress) {
    // Return Nth displayable node
    int elementNodeIndex = 0;
    for (int i=0; i<domNode.getChildNodes().getLength(); i++) {
    node = domNode.getChildNodes().item(i);
    if (node.getNodeType() == ELEMENT_TYPE
    && treeElement( node.getNodeName() )
    && elementNodeIndex++ == searchIndex) {
    break;
    return new XMLTreeNode(node);
    public int getIndex(TreeNode tnode) {
         if (tnode== null) {
              throw new IllegalArgumentException("argument is null");
         XMLTreeNode child=(XMLTreeNode)tnode;
         int count = getChildCount();
         for (int i=0; i<count; i++) {
              XMLTreeNode n = (XMLTreeNode)this.getChildAt(i);
              if (child.domNode == n.domNode) return i;
         return -1; // Should never get here.
    public class XMLTreeModel2 extends DefaultTreeModel
         private Vector listenerList = new Vector();
         * This adapter converts the current Document (a DOM) into
         * a JTree model.
         private Document document;
         public XMLTreeModel2 (Document doc){
              super(new XMLTreeNode(doc));
              this.document=doc;
         public Object getRoot() {
              //System.err.println("Returning root: " +document);
              return new XMLTreeNode(document);
         public boolean isLeaf(Object aNode) {
              return ((XMLTreeNode)aNode).isLeaf();
         public int getChildCount(Object parent) {
              XMLTreeNode node = (XMLTreeNode) parent;
    return node.getChildCount();
         public Object getChild(Object parent, int index) {
    XMLTreeNode node = (XMLTreeNode) parent;
    return node.getChildAt(index);
         public int getIndexOfChild(Object parent, Object child) {
    if (parent==null || child==null )
         return -1;
              XMLTreeNode node = (XMLTreeNode) parent;
    return node.getIndex((XMLTreeNode) child);
         public void valueForPathChanged(TreePath path, Object newValue) {
    // Null. no changes
         public void addTreeModelListener(TreeModelListener listener) {
              if ( listener != null
    && ! listenerList.contains( listener ) ) {
    listenerList.addElement( listener );
         public void removeTreeModelListener(TreeModelListener listener) {
              if ( listener != null ) {
    listenerList.removeElement( listener );
         public void fireTreeNodesChanged( TreeModelEvent e ) {
    Enumeration listeners = listenerList.elements();
    while ( listeners.hasMoreElements() ) {
    TreeModelListener listener =
    (TreeModelListener) listeners.nextElement();
    listener.treeNodesChanged( e );
         public void fireTreeNodesInserted( TreeModelEvent e ) {
    Enumeration listeners = listenerList.elements();
    while ( listeners.hasMoreElements() ) {
    TreeModelListener listener =
    (TreeModelListener) listeners.nextElement();
    listener.treeNodesInserted( e );
         public void fireTreeNodesRemoved( TreeModelEvent e ) {
    Enumeration listeners = listenerList.elements();
    while ( listeners.hasMoreElements() ) {
    TreeModelListener listener =
    (TreeModelListener) listeners.nextElement();
    listener.treeNodesRemoved( e );
         public void fireTreeStructureChanged( TreeModelEvent e ) {
    Enumeration listeners = listenerList.elements();
    while ( listeners.hasMoreElements() ) {
    TreeModelListener listener =
    (TreeModelListener) listeners.nextElement();
    listener.treeStructureChanged( e );
    The collapseAll, expandAll code (even though I m pretty sure that's not the problem since they work fine on a normal JTree):
        private void collapseAll(TreePath tp){
             if (tp==null) return;
             Object node=tp.getLastPathComponent();
             TreeModel model=tree.getModel();
             if (!model.isLeaf(node)){
                  tree.collapsePath(tp);
                  for (int i=0;i<model.getChildCount(node);i++){
                  //for (int i = node.childCount()-4;i>=0;i--){
                       collapseAll(tp.pathByAddingChild(model.getChild(node,i)));
                  tree.collapsePath(tp);
        private void expandAll(TreePath tp){
             if (tp==null) return;
             Object node=tp.getLastPathComponent();
             TreeModel model=tree.getModel();
             if (!model.isLeaf(node)){
                  tree.expandPath(tp);
                  for (int i=0;i<model.getChildCount(node);i++){
                  //for (int i = node.childCount()-4;i>=0;i--){
                       expandAll(tp.pathByAddingChild(model.getChild(node,i)));

    Hi,
    Iam not facing this problem. To CollapseAll, I do a tree.getModel().reload() which causes all nodes to get collapsed and remain so even if I reopen them manually.
    Hope this helps.
    cheers,
    vidyut

  • Expand/collapse button functionality on module pool screen

    Hi ,
    I want to design a module pool screen with a expand/collapse button on it.
    The desired functionality associated with this button would be something similiar to that available in ME21N screen. When the expand button is clicked it should open up a section of screen that allows the user to enter some parameter. Based on this parameter some selections from DB can be perfomed and then displayed below it.
    Any pointers on how to achieve this? Any kind of help would be appreciated.
    Regards-
    Harmeet Singh.

    example for three pushbutton with expand collapse .
    First of all define your push button as output field with icon tick in the pushbutton characteristick,
    then define this pushbutton in top_include
    include <icon>.
    data : push_a1 like icons-l4,
             push_a2 like icons-l4,
             push_a3 like icons-l4.
    data : a1 ,
             a2,
             a3.
    in pai of the screen
    suppose i had assign function code a1 ,a2 , a3 for repective pushbutton
    module user_command_9002 input.
      okcd = ok_code.
      clear ok_code.
      case okcd.
        when 'A1'.
          if a1 is initial.
            a1 = 'X'.
          else.
            clear a1.
          endif.
        when 'A2'.
          if a2 is initial.
            a2 = 'X'.
          else.
            clear a2.
          endif.
        when 'A3'.
          if a3 is initial.
            a3 = 'X'.
          else.
            clear a3.
          endif.
      endcase.
    endmodule.                 " USER_COMMAND_9002  INPUT
    define three seprate screen -group for three pushbutton say a1 a2 a3
    during pbo you can directly assign name of icon .
    if a1 is initial.
        push_a1 = icon_collapse.
      else.
        push_a1 = icon_expand.
      endif.
      if a2 is initial.
        push_a2 = icon_collapse.
      else.
        push_a2 = icon_expand.
      endif.
      if a3 is initial.
        push_a3 = icon_collapse.
      else.
        push_a3 = icon_expand.
      endif.
    loop at screen.
        if screen-group1 = 'A1'.
          if a1 = 'X'.
            screen-invisible = 1.
            screen-input = 0.
            modify screen.
          else.
            screen-active = 1.
            screen-invisible = 0.
            screen-input = 1.
          endif.
        elseif screen-group1 = 'A2'.
          if a2 = 'X'.
            screen-invisible = 1.
            screen-input = 0.
            modify screen.
          else.
            screen-active = 1.
            screen-invisible = 0.
            screen-input = 1.
          endif.
        elseif screen-group1 = 'A3'.
          if a3 = 'X'.
            screen-invisible = 1.
            screen-input = 0.
            modify screen.
          else.
            screen-active = 1.
            screen-invisible = 0.
            screen-input = 1.
          endif.
        endif.
      endloop.
    regards,
    Alpesh
    Edited by: Alpesh on May 28, 2009 10:28 AM

  • Change behaviour of Expand/collapse icon in JTree

    Want to change the behaviour of Expand/collapse icon in a JTree. Need help with the same. Thanks.

    Check: Hide and show region

  • Remove/hide expand/collapse icons

    Hi,
    I would like to remove/hide the expand/collapse icons and have a fixed navigation iView.
    Thanks in advance.
    Rgds,
    Janvi

    Hi Janvi,
    Probably to hide the collapse and expand icon you could go about with the theme editor , where u can set the url to these images as some blank image that coincides with ur background colour.
    To have a fixed navigation panel without scrolling ,probably you can change the the width of the navigation panel by changing the value defaultExpWidth in the file WAandNAVPanel.js file in the par file com.sap.layouts.framework.par from 220 pixels to a higher value.Later u need to upload the file back and restart ur system.
    Hope this helps,
    Regards,
    Uma.

  • Expand/Collapse button

    Does anybody know how to make a "Expand/Collapse" button (little orange triangle button)?
    I want to know if I can change the BOM in Sales Order to hide or show all child items (say the BOM is a Sales or Template BOM).
    Thanks,
    -Yan

    Hi Yan,
    It is not possible to change the BOM matrix in such a way.
    In addition the feature itself is planned to be available in version 2005...
    ...and even then you would have to use a workaround: hide the original matrix and display your own collapsible matrix including all the handling needed + when saving do some more handling to serialize the changes into the DB...
    Regards,
    Frank

  • JTree expand/collapse

    how to check if a node in a JTree is expanded???

    In my JTree there are couple of nodes which are all initially expanded.
    User collapses couple of nodes in the JTree while others are still expanded.
    Then, if user deleted a node from a JTree would like to keep all expanded nodes as expanded and collapsed nodes as collapsed.
    How to do this?
    Thanks.

  • Remove the expand/collapse image for af:treeTable

    I am showing some data in a treeTable, which some rows will not have any further childs. How can I remove the expand/collapse image for those rows in the component <af:treeTable> ?
    Regards,
    Uday

    Hi,
    according to http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/exchange/jsf/doc/tagdoc/core/treeTable.html you can only hide the expand/hide all link
    Frank

Maybe you are looking for

  • Accounting postings for subcontract PO goods receipt

    Hi, Can someone please explain the accounting postings that occur when a subcontract PO is received?  I understand the usual inventory and GR/IR account entries.  But there are 2 additional account entries for transaction keys FRL and BSV.  These app

  • InDesign overset text indicators

    I have a document in which several pages have overset text indicators, but the text is not overset. There is actually space for more text within the text frames.  I have not been able to see how to get rid of the overset indicators.

  • "The application "Adobe Flash CC" can't be opened -600"

    error message appears when I click .fla or .as files - "The application "Adobe Flash CC" can't be opened -600" I think this has started only since I installed Mavericks. I can open the files from within the Flash app but not by clicking the desktop f

  • Framemaker in Creative Cloud?

    Why is Framemaker not included in the Creative Cloud? Will it ever be?

  • Mavericks upload.15"MacBook Pro 10.6.8(2008) 38GB space, 3GB mem, core 2 Duo.

    I have a 15" MacBook Pro (purchased in 2008) OS 10.6.8 Snow Leopard 38GB of available space on my HD 3 GB of memory Processor: Intel Core 2 Duo    I forgot to add this:  2.16 GHz Why won't Mavericks upload? I have double checked my external HD and I