How to disable selection of root node in JTree

Hi all! Thanks for taking a minute to read my post!
I am writing a really basic JTree for showing a list of items.
Here is some of the code:
/** Create a basic tree **/
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Title");
DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
JTree tree = new JTree(treeModel);
/** Method to return the string of the current highlighted selection **/
public String getSelectionString()
DefaultMutableTreeNode node =
tree.getSelectionPath().getLastPathComponent();
return (String)node.getUserObject();
I would like to disable selection of the root node of my JTree.
Thus, if I make a call to getSelectionString() above, it would return null instead of the string that represents the root label.
I have read the following forum on disabling various TreePaths and TreeNodes in a JTree:
http://forum.java.sun.com/thread.jsp?forum=57&thread=224691
This forum suggests implementing the TreeSelectionListener interface and the TreeSelectionModel class and over-riding the addSelectedPath() methods. I tried this suggestion, and I was able to enable and disable the different children of the Jtree, but the root of the JTree would not disable.
I suppose that I could just simply remove the visibility of the root node, but I really want to avoid that option if possible.
Wait --- let me be clear ---- I want to disable the selection of the root node only - still allowing selection of all its children.
Any suggestions?
Am I missing something really simple here?
Did I explain my problem clearly?
Thanks in advance!
jewels

simply try this..
in the
public void valueChanged(javax.swing.event.TreeSelectionEvent event);
method of TreeSelectionListener impelentation get the
TreePath tp = event.getPath();
from TreePath get the component and then remove the selection from the treePath if it is the node u were checking/root node in this case
tree.getSelectionModel().removeSelectionPath(tp);
Try out....

Similar Messages

  • How to disable "Selection Security" in a correct way?

    hi experts!
    how to disable "Selection Security" in a correct way?
    !http://img689.imageshack.us/img689/2748/28668107.png!
    thanks!

    Hi...
    Open "Catalog Manager" and
    navigate to Shared -> "Shared Folder Name" (ex: Sample Sales) -> _Portal.
    Here you find all dashboards. Open the dashboard that you already enabled selection. In that dashboard folder you find one more folder with name: _selections*
    Delete the _selections* folder.
    You will get Enable option again in front end.
    All the best

  • How to Programatically select a Tree Node ?

    Hi,
    JDV = 11.1.1.6
    I don't know about the answer yet! but the question is simple ;)
    say I'm viewing departments Info in a tree (Code , Name)
    How can I select a particular node in my tree using "Code" value as the parameter?
    Thank you ,
    Shahab

    Hi Shahab,
    Please find below a custom method to programmatically select a node during a disclose event by the user:
    public void onRowDisclosure(RowDisclosureEvent rowDisclosureEvent) {
         RichTree tree = (RichTree)rowDisclosureEvent.getSource();
         RowKeySet disclosedRows = rowDisclosureEvent.getAddedSet();
         RowKeySet selectedRows = tree.getSelectedRowKeys();
         selectedRows.clear();
         if (disclosedRows.size() == 1){
         Object disclosedNode = disclosedRows.iterator().next();
         selectedRows.add(disclosedNode);
         makeCurrent(tree, disclosedRows);
         tree.setSelectedRowKeys(selectedRows);
         AdfFacesContext adfFacesContext =
         AdfFacesContext.getCurrentInstance();
         adfFacesContext.addPartialTarget(tree.getParent());
    Hope this helps in your requirement.
    Best Regards,
    Ankit Gupta

  • How set disable select matrix column header

    How set disable select matrix column header same Inventory-->Pick List Form
    Thanks Advance.

    Hi ,
    do u mean Price List Form Header...
    If Yes Means Try the Following,
    select case pVal.FormType
    case "155"
    Select Case pVal.Before_Action
    case True
    select case pval.ItemUid
    case "3"
    Select Case pVal.EventType
    Case SAPbouiCOM.BoEventTypes.et_CLICK
    if pval.row = 0  Then BubbleEvent = False : Exit Sub
    End Select
    End Select
    End Select
    Regards,
    Ganesh k

  • How to disable selection parameter for a particular radio button

    hi experts,
    How to disable selection parameter(bukrs) for a particular radio button 'radio1'.

    hi,
    Check This Code (copy paste and run it ).
    U have to use MODIF ID along with the parameter.
    *----------------Option
    *---Background
    *---Summary Report
    PARAMETERS       : p_backgd RADIOBUTTON GROUP rad1
                       USER-COMMAND radio DEFAULT 'X'.
    PARAMETERS       : p_sumrep RADIOBUTTON GROUP rad1 .
    *----------------File
    PARAMETERS       : p_sumfl TYPE char255 modif id ABC  .
    PARAMETERS       : p_detfl TYPE char255 modif id ABC.
    *---------------Activate & Deactivate Screen Fields--------------------*
    AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF p_sumrep = 'X'.
          IF screen-group1  = 'ABC'.
            screen-input  = '0'.
            MODIFY SCREEN.
          ENDIF.
        ENDIF.
      ENDLOOP.
    <b>Please Reward Points & Mark Helpful Answers</b>
    To mark Helpful Answers ;click radio Button next to the post.
    RadioButtons
    <b>o</b> Helpful Answer
    <b>o</b> Very helpful Answer
    <b>o</b> Problem Solved.
    Click any of the above button next to the post; as per the anwers
    <b>To close the thread; Click Probelm solved Radio Button next to the post ,
    which u feel is best possible answers</b>

  • How do i add a root node to a XMLType

    Hi all
    I have a problem inserting a root node in a xml document generated by DBMS_XMLGEN.newcontextfromhierarchy. The function get_site_map_nodes generates a document like this:
    <?xml version="1.0"?>
    <siteMapNode f_page_id="1" title="rot" PATH="1">
    <siteMapNode f_page_id="2" title="1.1" PATH="1.1">
    <siteMapNode f_page_id="4" title="1.1.1" PATH="1.1.1"/>
    </siteMapNode>
    <siteMapNode f_page_id="3" title="1.2" PATH="1.2"/>
    <siteMap/>
    </siteMapNode>
    This is correct but i want to add a root node so the result shows as below:
    <?xml version="1.0"?>
    <siteMap>
    <siteMapNode f_page_id="1" title="rot" PATH="1">
    <siteMapNode f_page_id="2" title="1.1" PATH="1.1">
    <siteMapNode f_page_id="4" title="1.1.1" PATH="1.1.1"/>
    </siteMapNode>
    <siteMapNode f_page_id="3" title="1.2" PATH="1.2"/>
    <siteMap/>
    </siteMapNode>
    </siteMap>
    The problem is that i have no clue how to accomplish this.
    Best regards
    Daniel Carlsson
    PACKAGE BODY PKG_PAGE_STRUCTURE
    IS
    FUNCTION get_level_path (in_page_id IN page_structure.f_page_id%TYPE)
    RETURN VARCHAR2
    IS
    l_path VARCHAR2 (4000) := '';
    BEGIN
    SELECT MAX (SYS_CONNECT_BY_PATH (f_show_order, '.'))
    INTO l_path
    FROM page_structure
    START WITH f_page_id = in_page_id
    CONNECT BY PRIOR f_parent_page = f_page_id;
    l_path := RTRIM (l_path, '.');
    RETURN l_path;
    END get_level_path;
    FUNCTION get_site_map_nodes (in_page_id IN page_structure.f_page_id%TYPE)
    RETURN XMLTYPE
    IS
    qryctx DBMS_XMLGEN.ctxhandle;
    l_xml XMLTYPE;
    BEGIN
    qryctx :=
    DBMS_XMLGEN.newcontextfromhierarchy
    ('select level, xmlelement("siteMapNode", XMLAttributes(f_page_id as "f_page_id",
    f_title_phrase as "title", pkg_page_structure.get_level_path(f_page_id) as path))
    FROM PAGE_STRUCTURE
    START WITH f_page_id = :in_page_id
    connect by f_parent_page = prior f_page_id
    ORDER siblings BY f_show_order'
    DBMS_XMLGEN.setbindvalue (qryctx, 'in_page_id', TO_CHAR (in_page_id));
    l_xml := DBMS_XMLGEN.getxmltype (qryctx);
    DBMS_XMLGEN.closecontext (qryctx);
    RETURN l_xml;
    END get_site_map_nodes;
    END PKG_PAGE_STRUCTURE;
    CREATE TABLE page_structure
    (f_page_id NUMBER(10,0) NOT NULL,
    f_parent_page NUMBER(10,0),
    f_show_order NUMBER(10,0),
    f_title_phrase VARCHAR2(20),
    f_created_by NUMBER(10,0),
    f_created_date DATE,
    f_updated_by NUMBER(10,0),
    f_updated_date DATE)
    INSERT INTO page_structure
    (F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
    VALUES
    (1,NULL,1,'rot',1,'30-MAR-2006',NULL,NULL)
    INSERT INTO page_structure
    (F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
    VALUES
    (2,1,1,'1.1',1,'30-MAR-2006',NULL,NULL)
    INSERT INTO page_structure
    (F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
    VALUES
    (3,1,2,'1.2',1,'30-MAR-2006',NULL,NULL)
    INSERT INTO page_structure
    (F_PAGE_ID,F_PARENT_PAGE,F_SHOW_ORDER,F_TITLE_PHRASE,F_CREATED_BY,F_CREATED_DATE,F_UPDATED_BY,F_UPDATED_DATE)
    VALUES
    (4,2,1,'1.1.1',1,'30-MAR-2006',NULL,NULL)
    /

    Please try below steps.
    1. Complete Prerequisite for adding cluster node
    2. Verify the node is accessible to all other nodes in the cluster. Run the following command from the existing node in the cluster.
    cluvfy stage -pre crsinst -n newNode
    3. Run cluvfy from any existing node
    cluvfy stage -pre nodeadd -n <New Node>
    Note : If cluvfy in above step shows any errors fix those and then proceed with this step
    4. Change Directory to Clusterware Home and execute addNode scripts from any existing node.
    cd $CRS_HOME/oui/bin
    ./addNode.sh -silent "CLUSTER_NEW_NODES={ <NewNode > } CLUSTER_NEW_PRIVATE_NODE_NAMES={ <Interconnect >} CLUSTER_NEW_VIRTUAL_HOSTNAMES={ < Virtual Host Name >}"
    At the end of addNode, script will prompt to run for root.sh on newly added node.
    5. Verify Node is successfully added
    cluvfy stage -post nodeadd -n <NewNode >
    6. Verify CRS Stack is running on the new Node.
    $CRS_HOME/bin/crs_stat -t
    7. To extend the Oracle RAC Installation to include the new Node, run addNode from $ORACLE_HOME/oui/bin from existing node in the cluster
    cd $CRS_HOME/oui/bin
    ./addNode.sh
    When OUI displays the Specify Cluster Nodes to Add to Installation window, select the node to be added, then click Next .
    Verify the summary and run root.sh on new node when it prompts.
    8. Adding New Instance on the New Node
    $CRS_HOME/bin/lsnrctl status
    9.Run $ORACLE_HOME/bin/dbca from any of the existing RAC Instances Oracle Home.
    Select Oracle Real Application Clusters database , and then click Next .
    Select Instance Management , and then click Next .
    Select Add an Instance , then click Next .
    Click Next to accept default instance name or it can be changed.
    Check the summary window.
    Note: Please check these steps in test environment first.
    HTH

  • How to disable 'select display' on screen sharing?

    One improvement in Lion is Screen Sharings 'asking' of the current logged in user as to whether or not it is ok to share the screen.  While I understand the need for this in a multi-user environment, this is a unnecessary level of feature for most home users.  In fact, it's been a total pain and I'd like to know how to disable it.  Trying to remote support parents has become virtually impossible as they are unsure as to what it means to allow screen sharing when I attempt to connect.
    Anyone know how to disable this feaute and let Screen Sharing work as it did pre-lion?

    Apple menu > System Preferences > Sharing > Screen Sharing > Allow access for: account you want to log into
    Connect as that user.

  • How to change a generated root node for a hierarchy?

    Hello,
    we are loading hierarchies from an ECC system. Some of those hierarchies don't have a root node in the source system.
    For those hierarchies, the root node is generated during the loading. This node is generated in english (ie : FUNDS CENTER HIERARCHY for fund centers). Is there a way to change the description and the technical name of this node to have it in another language.
    We have tryied to change the language of ALEREMOTE in BI but it did not solve this problem.
    Thanks,
    Philippe

    Hi Simon,
    the language that triggered the loading was french.
    BI Learner,
    - to create a custom hierarchy in a BI system, you can use RSH1 transaction.
    - if you want to load it from a SAP source system, you can use standard datasource provided in the business content (usually named *_HIER)
    -if you need to load it from a flat file, you can follow the steps of this blog, it will help you:
    Hierarchy Upload from Flat files
    you can have more information about hierarchies on the help.sap web site :
    http://help.sap.com/saphelp_nw70/helpdata/EN/a8/6b023b6069d22ee10000000a11402f/frameset.htm
    Regards,
    Philippe

  • How to add value to Root node in message mapping i.e. ns1:sObjects to ns1:sObjects xsi:type="Account"

    Hi Experts,
      please provide me any  UDF or Java or XSLT maaping code to add text into the root node of the payload i.e. my target Payload will be like
    <ns1:sObjects>
    <ns2:Id>123</ns2:Id>
    <ns2:name>Test message <n/s2:name>
    </ns1:sObjects>
    and i have to get it like
    <ns1:sObjects xsi:type="Account">
    <ns2:Id>123</ns2:Id>
    <ns2:name>Test message <n/s2:name>
    </ns1:sObjects>
    Regards,
    Yugandhar

    HI Yugandhar,
    In case of sales force, the can team will provide you a WSDL, In that WSDL you can manually edit the type:Account and can use the same while mapping.
    pls find the below screen shot, it will give you a better idea,
    pls let me know if you any further issues regarding.
    Pls Mark it as a correct answer if it is.
    Thanks,
    Prasad.

  • Highlight root node in jtree

    When I build my JTree, I have just one single node, the root node. So in order to highlight it, I basically do setSelectionRow(0);, however this is not highlighting the node as if a user clicked it with a mouse, WHEN THE APPLICATION COMES UP.
    Once the application comes up, if I click on that node or for that matter any other node, they get highlighted in blue. It's only upon initialization that this doesn't work.
    Here's a snippet of the sample code:
    tree = new JTree();
    tree.setCellRenderer(new RateManagerTreeCellRenderer());
    I've also tried the setSelectionPath(TreePath path) method without any success. I think that my Custom TreeCellRenderer could be the culprit. If someone could try to duplicate this problem by using the code below of my RateManagerTreeCellRenderer, I would appreciate it.
    public class RateManagerTreeCellRenderer extends DefaultTreeCellRenderer
    private static Color oldColor = Color.BLACK;
    private static Color newColor = Color.BLUE;
    private HashMap iconMap = new HashMap();
    public Component getTreeCellRendererComponent(
              JTree tree, Object value,
              boolean selected, boolean expanded,
              boolean leaf, int row,
              boolean hasFocus)
    super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value;
    Object userObject = treeNode.getUserObject();
    if (userObject instanceof NameAndID)
    NameAndID nameAndID = (NameAndID)userObject;
    int count = nameAndID.getItemCount();
    if (count > 0 && !selected)
    setForeground(newColor);
    else if (!selected)
    setForeground(oldColor);
    this.setToolTipText(((NameAndID)userObject).toString());
    String type = nameAndID.getType();
    setIcon(type);
    return this;
    }

    Do you mean setting the focus on that node? Or are you talking about some custom painting to put a background behind it? We can't help you much if you don't ask a more specific question with more details about what you're trying to do.

  • How to set the default tree node in JTree?

    I want to set a default tree node in JTree when start the program,
    what is the method or the function to call?
    Thanks~

    If you by "default" mean "selected", then you can use one of the setSelectionXXX methods in the JTree API.
    If you by "default" mean something else, never mind this post :-)

  • Is it possible to set the root node of JTree by default close???? Pls Help

    Hello frnz,
    I am working on JTreeTable and rt now i am facing a problem , in which i have to keep the root of the JTree by default close,
    So please suggest me to do what for this.

    How about
    JTree.collapseRow(0)

  • How to disable selective cells in a column of a table?

    Hi
    I have a Table UI element having 5 columns. 4 of this are non-editable and only one is editable i.e. having input field . The data is picked from the backend. The 5th column also gets default data from the backend, which the user can later on change.
    But there is a condition, that only the input fields from that row onwards should remain enabled whose month field matches the current month. Rest all should become disabled or invisible.
    I worte the code in the wdModifyView() which picks the current date, and then in a loop it checks all the rows for the condition. If it matches the condition, it comes out of the loop, else it sets the enable property of input field to false.
    But when i run this application, all the cells become disabled, not selective cells.
    Is there a way in which I can sort this problem, any API using which i can access each cell by its row number and column number and then disable it.
    If anybody could please help, it is urgent.
    Thanks & regards,
    Anupreet

    Anupreet,
    Create a subnode with cardinality 1..1 and boolean attribute IsEnabled right under your data node. Write a supply function for this subnode, and set boolean attribute value depending on month in parentElement (parameter of supply function). Then bind InputField "enabled" property to this boolean attribute.
    VS

  • Using Report Catergory and how to Disable 'Select Range button on screen'

    Hi All,
    I am using logical Database PNPCE and I have created my own report category and I would like to disable the 'Select Ranges'
    button that shows to the right of my field for Organization Unit as I would like them to be restricted to only one entry.
    thank you,
    KW

    I have tried this in my INITIALIZATION of my program but no luck... how is there a way to accomplish this? Remember I am trying to restrict the range selection on my report category that is attached to my LDB PNPCE.
    * Define the object to be passed to the RESTRICTION parameter
      DATA lv_restrict TYPE sscr_restrict.
    * Auxiliary objects for filling RESTRICT
      DATA lv_opt_list TYPE sscr_opt_list.
      DATA lv_***      TYPE sscr_***.
    * KIND = 'A': applies to all SELECT-OPTIONS
      MOVE: 'A'    TO lv_***-kind,
      '*'          TO lv_***-sg_main,
      'NOPATTERN'  TO lv_***-op_main,
      'NOINTERVLS' TO lv_***-op_addy.
      APPEND lv_*** TO lv_restrict-***_tab.
      CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
        EXPORTING
       program                      = sy-repid
       restriction                  = lv_restrict
    *   DB                           = ' '
    * EXCEPTIONS
    *   TOO_LATE                     = 1
    *   REPEATED                     = 2
    *   SELOPT_WITHOUT_OPTIONS       = 3
    *   SELOPT_WITHOUT_SIGNS         = 4
    *   INVALID_SIGN                 = 5
    *   EMPTY_OPTION_LIST            = 6
    *   INVALID_KIND                 = 7
    *   REPEATED_KIND_A              = 8
    *   OTHERS                       = 9
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Edited by: Keith Warnock on Jan 13, 2011 8:30 PM

  • How to disable selection of  End Date depending on start Date.

    Hello,
    I have  2 DatePicker controls
    1) Start Date
    2) End Date
    When I select a start date  in  date picker depending on that  it should disable the  selection of  dates less than  Start date in End date Date Picker.
    Could anyone please provide solution for it.
    Thanks & regards,
    Viswanath

    You can always check UI5 core files and extend it. FYI, most of UI5 calendars are based on "MobileScroll" UI library, e.g.
    DateTimeInput - Mobiscroll - Demos and Examples - Date &amp;amp; Time - Date with min and max
    DatePicker - Mobiscroll 2.15.1 Documentation - Calendar
    Below you can find few extension examples:
    sap.m.DateTimeInput extend- JS Bin - Collaborative JavaScript Debugging&lt;/title&gt;  &lt;link rel=&quot;alternate&quot; type=&quot;application/jso…
    sap.m.DatePicker extend -> JS Bin - Collaborative JavaScript Debugging&lt;/title&gt;  &lt;link rel=&quot;alternate&quot; type=&quot;application/jso…
    Regards,
    Vladimir

Maybe you are looking for

  • JMS Adapter Message Selector Problem...

    Hi I have set the following in the invoke before producing the message and dropping on the queue <invoke name="Invoke_1" partnerLink="adapt" portType="ns1:Produce_Message_ptt" operation="Produce_Message" inputVariable="Invoke_1_Produce_Message_InputV

  • Camera with labview

    hello i want to use a usb camera with labview i searched in the forum and i found many discusions about IMAQ driver fro usb camera i have dowloaded many of the VIs and every time when i open the VI in labview it skes me to load a sub vis that i dont

  • Sat A100-593: Should I install 64-bit or 32-bit version of Win Vista

    A100-593 Centrino Duo T2300, 1 Gb RAM 533 FSB I have already installed 32-bit version. Everything works fine. But I read 64 bit can give problems with hardware laptop (lack of 64-bit drivers) http://www.tech-recipes.com/microsoft_vista_tips1426.html

  • Can't reset ePrintCenter password

    Hi, I am trying to reset my ePrintCenter password but when I click the reset password url in the email I get: SERVER ERROR Oops! Something just went wrong with our server. Try refreshing the page. I've tried about 10 times and same issue each time, c

  • Start time error in EC50E (Move-in creation)

    Dear all, We are working on ISU Upgrade project, earlier ISU version was 4.6c and now we are moving to ECC 6. Now while integration testing in ECC 6, we are facing a error (message) while creating a move-in (EC50E)for a given BP on Premise level. Thi