Focusing userObject of a Node

Hi everyone!
I have the following problem:
my JTree has DefaultMutableTreeNodes. Every userObject of a node is a JPanel with a JLabel and a JComponent.
Now I want to put the focus on the JComponent !!!
it works, by clicking on the JComponent, but not if i go through the tree with the cursor-keys (although the selection is changed to the nodes!)
requestFocusInWindow() does not work, because isDisplayable() of the JComponent returns false!
PEASE HELP !!!
Thanks for any suggestions !

Hi,
May be you need this :
DECLARE
htree ITEM;
parent_node NODE;
BEGIN
-- Find the tree itself.
htree := Find_Item('tree_block.htree3');
-- Get the parent of the node clicked on.
parent_node := Ftree.Get_Tree_Node_Parent(htree, :SYSTEM.TRIGGER_NODE);
...END;
And then
node_value := Ftree.Get_Tree_Node_Property(htree, :SYSTEM.TRIGGER_NODE, Ftree.NODE_VALUE);

Similar Messages

  • JTree - focusing userObjects (JComponents)

    Hi everyone!
    I have the following problem and i am despairing:
    my JTree has DefaultMutableTreeNodes. Every userObject of a node is a JPanel with a JLabel and a JComponent (normally JTextFields or JComboBoxes).
    Now I want to put the focus on the JComponent !!!
    it works, by clicking on the JComponent, but not if i go through the tree with the cursor-keys (although the selection is changed to the nodes!)
    requestFocusInWindow() does not work, because isDisplayable() of the JComponent returns false!
    PEASE HELP !!!
    Thanks for any suggestions !

    Hi Denis !
    I think I haven't configured the editor in the right way !?! Here's more information:
    I have a cellRenderer, a cellEditor and a selectionListener.
    From the selectionListener I call the startEditing Method:
    public void valueChanged(TreeSelectionEvent e) {
          TreePath tp = e.getNewLeadSelectionPath();
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) tp.getLastPathComponent();
          if (node == null)
            return;
          if (MyTreeCellEditor.isCellEditable(node))
         theTree.startEditingAtPath(tp);
    }startEditingAtPath throws a NullPointerException if I click on a Node
    at javax.swing.plaf.basic.BasicLookAndFeel.compositeRequestFocus(BasicLookAndFeel.java:1748)
    and going through the tree with the cursor-keys doesn't work at all !!?!?!?
    the cellEditor Method:
    public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected,
                                                boolean expanded, boolean leaf, int row) {
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
          Object userObject = node.getUserObject();
          if (userObject instanceof MyPanel)
            return (MyPanel) userObject;
           // else:
          return super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
    }Thanks for help !
    Andreas

  • ADF Tree setting focus back to parent node after deletion of child node

    Hi,
    Is there a way to get the focus back to the parent node (or rather any particular node) in a tree?
    I have a use case where we need to get the focus back to the parent node after a child node is deleted.
    Currently the focus is shifted to the next node in the tree, but the need is to get the focus shifted back to the parent node. Also the parent node should be re-invoked to populate to get the latest status after deletion of the child node.
    Any help/pointers?
    Thanks

    Thanks for the reply Frank.
    I saw the link http://sreevardhanadf.blogspot.in/2012/07/showing-next-row-as-current-row-after.html
    However the issue is since I am using custom created tree using POJO tree item (composite object).
    calling myTree.getWrappedData() doesn't gives me a handle to JUCtrlHierBinding and subsequent access to JUCtrlHierNodeBinding.
    my program gives me data like -
    List<MyTreeItem> treeData = (List<MyTreeItem>)treeModel.getWrappedData();
    because my tree model is build using -
    treeModel = new ChildPropertyTreeModel(items, "children");
    where items is List of <MyTreeItem>
    Hence I am unable to get a handle using -
    List nodeParentList = nodeParent .getKeyPath();
    I am programmatically able to invoke the parent node to get the fresh data, only issue is the focus/selection of that node is not happening
    Is there a way around?
    Thanks
    Sachin

  • How to move focus from one JTree node to another one and then back again?

    Hi all!
    Say I have a very simple JTree
    package main;
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    import javax.swing.JTree;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.tree.DefaultMutableTreeNode;
    public class SelectableTree extends JFrame implements TreeSelectionListener {
        public static void main(String[] args) {
            new SelectableTree();
        private JTree tree;
        private JTextField currentSelectionField;
        public SelectableTree() {
            super("JTree Selections");
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent event) {
                    System.exit(0);
            Container content = getContentPane();
            DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
            DefaultMutableTreeNode child;
            DefaultMutableTreeNode grandChild;
            for (int childIndex = 1; childIndex < 4; childIndex++) {
                child = new DefaultMutableTreeNode("Child " + childIndex);
                root.add(child);
                for (int grandChildIndex = 1; grandChildIndex < 4; grandChildIndex++) {
                    grandChild = new DefaultMutableTreeNode("Grandchild "
                            + childIndex + "." + grandChildIndex);
                    child.add(grandChild);
            tree = new JTree(root);
            tree.addTreeSelectionListener(this);
            content.add(new JScrollPane(tree), BorderLayout.CENTER);
            currentSelectionField = new JTextField("Current Selection: NONE");
            content.add(currentSelectionField, BorderLayout.SOUTH);
            setSize(250, 275);
            setVisible(true);
        public void valueChanged(TreeSelectionEvent event) {
            currentSelectionField.setText("Current Selection: "
                    + tree.getLastSelectedPathComponent().toString());
    }All I need is to move focus from currently selected node, to some other node (does not matter which one), then to "sleep" for a second and finally move it back to return selection to the previously selected node. The only question is how do I do this?

    Use a Seperate Thread to do it:
    Runnable r = new Runnable() {
        public void run() {
                   int k=tree.getSelectionRows()[0];
                   DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                                if(node.getNextSibling()!=null)
                                     tree.setSelectionRow(k+1);
                                else
                                     tree.setSelectionRow(k-1);
                                sleepe(k);
    public void sleepe(int i){
                         try{
                                Thread.sleep(1000);
                                     }catch(Exception e){
                                         e.printStackTrace();
                                  tree.setSelectionRow(i);
        }Then start this thread in a mouse click event(or any other similar),but not in TableSelectionListener because >>if the current selected row is 1 then it will execute the valueChanged method of TableSe..li. and we set the selected row to 2 then again it will execute the valueChanged method of TableSe..li.It will repeat till something,or in error.
    tree.addMouseListener( new MouseListener(){
    public void mouseClicked(MouseEvent e) {
                       new Thread(r).start();
    public  void mouseEntered(MouseEvent e) {
    public  void mouseExited(MouseEvent e) {
    public  void mousePressed(MouseEvent e)     {
    public  void mouseReleased(MouseEvent e) {
      });Note:it worked perfectly for me. So add all the above in the right place and import necessary.It will execute perfectly.

  • Is there a way to retain the focus of an expanded node in ADF Tree?

    Hi! All,
    We have a requirement that the tree nodes should be expanded and collapsed(traversed,in a word), not only by mouse clicks but also using Keys(Tab+Enter keys).
    This is working fine with ADF Tree, but the problem I'm facing is that the tree node that was expanded using keys is losing focus(though the node that is expanded using mouse click is retaining focus).
    Is there a way to programmatically access the node that is expanded and retain focus on that node, even if the node expansion is done through Key event rather than mouse event?
    awaiting your suggestions,
    Thanks and Regards,
    Samba

    There are some tricky ways to adjust settings within a template (see: this) I think an easier solution is to make 3 or four templates that cover the range you are likely to encounter.  Like a 2 second, 3 second, 5 second, etc... duration template. Label them appropriately and hand over that template toolset to your colleague.
    Patrick

  • APEX Tree.  Keep focus on expanded leaf node.

    How do I prevent my tree from jumping back to the top when I expand a leav node that is below the screen scroll. I have a single parent of CORP with about 30 leaf nodes as its direct children. I have to scroll down to expand a node towards the bottom of the list. When I scroll down and expand, the page refreshes and jumps back to the top so now I have to scroll down again to expand the next node, etc. My current Tree Qurey is like
    select CHILD_ID id,
    PARENT_ID pid,
    CASE WHEN CHILD_ID = :P23_TARGET THEN
    CASE WHEN :P23_STATUS = 'Target Up' THEN
    '<span styl="color:green;">' || ITEM_NAME || '</span>'
    ELSE ITEM_NAME
    END
    ELSE
    ITEM_NAME
    END name,
    'f?p=&APP_ID.:23:'||:SESSION||'::NO::P23_TARGET:'||CHILD_ID link,
    null a1,
    null a2
    from CORP_SVR_HRCHY_VW

    Hi,
    You have to use the Anchor ID functionality of a browser - this allows you to add #id to the end of the url where id refers to the id attribute of the item that should receive the focus when the page is reloaded.
    As an example: [http://apex.oracle.com/pls/otn/f?p=33642:200]
    This, of course, requires a bit of setting up, but is easily doable.
    For this example, my SQL statement for the tree is:
    SELECT 1 ID, NULL PID, 'Top' NAME, NULL LINK, NULL A1, NULL A2 FROM DUAL
    UNION ALL
    select "EMPNO" id,
           1 pid,
           "ENAME" name,
           'f?p=' || :APP_ID || ':200:' || :APP_SESSION || '::::P200_EMPNO:' || EMPNO || '#node' || EMPNO link,
           'node' || EMPNO a1,
           null a2
    from "#OWNER#"."EMP"You will note that the URL contains *'#node' || EMPNO* at the end of the link - for an EMPNO of 1234, this would add *#node1234* to the end of the URL. You will also note that I've added *'node' || EMPNO* to the A1 column - whatever I add into this column becomes available for use in the output by referencing it as #A1# in the template. On the tree's template definition, wherever there is an A tag, I've included:
    ID="#A1#"as an attribute of the tag. For example, on the "Name Link Anchor Tag" setting, I have:
    &lt;a href="#LINK#" ID="#A1#"&gt;#NAME#&lt;/a&gt;and, wherever #A1# appeared outside of an A tag, I have removed it (otherwise, the "node1234" text would appear at that point in the page).
    Andy

  • How to get VO row of the focus node in hGrid

    Hello Everyone,
    I am developing custom screen with the following layout.
    Header: Top Node Details
    <Table "contains some details about top-node or node in focus in hGrid">
    Header: Organization Hierarchy
    <hGrid here>
    My requirement is to display some additional details about top node of the hierarchy in <table> above. If user sets focus on a particular node in hGrid , then <table> shall display some details about new top node (which is in focus). This is where trouble starts, how do I get the VO row of the top node in focus?
    My initial idea was to capture PPR event = "focus" in submitFormRequest and use method getFocusRoot . Below is part of the code:
    OARenderingContext renderingcontext = pageContext.getRenderingContext();
    HGridDataProxy dataproxy = hGrid.getProxy().getFocusRoot();
    DataObject focus = dataproxy.getFocusRoot(renderingcontext, dataproxy(renderingcontext, (DataObject) ???????));
    If this is a right appraoch ? If yes , what should be instead of question marks ?
    Thank you ,
    Aivars.
    .

    OK, we can play this game on and on...
    I'll ask for a use case (http://en.wikipedia.org/wiki/Use_case) and you don't give any info we don't already know. After an other 10 posts we probably know what you real problem is and can give you the advice which you could have gotten in the fist place.
    So please take some time and describe the problem as if you would ask your mother for help. Tell us how the data model is build and how the VO are related. Is there any input from an user involved? Which information from the other view do you need? How do you get to the doDML method? Is there a button in the ui involved?
    Timo

  • Gainer Focus and Lost Focus

    How implements the methods to gainer focus and lost focus?
    Thanks

    Use a node.focusedProperty() change listener to know when a field gains or loses focus.
    Call node.requestFocus() to ask for focus (for some reason I have to wrap this in Platform.runLater to get it to actually do anything).
    Call node.setFocusTraversable(false) if you don't want the user to be able to tab to the node, but still be able to click on the node to give it focus.
    Call node.setDisable(true) if you don't want the node to be focusable at all.
    I'm not sure how the focus traversable order is calculated, perhaps the order that items are added to the scene?
    Not sure how you would create a custom focus traverse if you needed one.
      @Override public void start(Stage primaryStage) {
        final TextField tf1 = new TextField("First but not initially focused");
        final TextField tf2 = new TextField("Second initially focused");
        Platform.runLater(new Runnable() { public void run() { tf2.requestFocus(); } });
        final TextField tf3 = new TextField("Can focus by clicking on, but not by tabbing to.");
        tf3.setFocusTraversable(false);
        final TextField tf4 = new TextField("Cannot focus at all.");
        tf4.setDisable(true);
        tf1.focusedProperty().addListener(new ChangeListener<Boolean>() {
            public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
              if (newValue) {
                System.out.println("First text field gained focus");
              } else {
                System.out.println("First text field lost focus");
        VBox root = new VBox(); root.setSpacing(5);
        root.getChildren().addAll(tf1, tf2, tf3, tf4);
        primaryStage.setScene(new Scene(root, 300, 100));
        primaryStage.show();
      }

  • Set for specific nodes in JTree specific rowheight

    Hi,
    I got a JTree with different components for the nodes userobject.
    some nodes got JTextAreas as userobject. Those nodes got the same height as all other nodes. This is the problem ... the nodes who contains JTextAreas should have a larger rowheight - to paint their content well. But there is only a method to specify the of the height of all rows in a JTree, anyone knows a good solution?
    thx
    null
    Message was edited by:
    Olek

    From the JTree.setRowHeight documentation:
    "Sets the height of each cell, in pixels. If the specified value is less than or equal to zero the current cell renderer is queried for each row's height."
    So try tree.setRowHeight(0);

  • Highlight an ADF tree node when it is clicked

    Hello every onei ,
    Does anybody has any idea how to highlight an ADF tree node when it is clicked ?
    Here is my scenario:-
    I have a popup which has a tree component on left and when we click on any node in the tree we have to display the corresponding page on right side.
    As the tree is common for all pages in the popup, i created an XHTML template with tree. All the treenode pages will use this template to display the tree.This template i am using to implement in rest of the pages.
    So when i click any link on this tree will load the corresponding JSP. But i am loosing focus. i mean selected node is not highlighting. Because we are loading the entire target page with template.
    Could any let me know how to highlight the tree node ?
    The Main problem is we are not using ADF controllers. We are using managed beans, these managed beans attached to the JSPX pages.
    Kindly guide me if any one knows solution.
    Thanks & Regards,
    Sai Sravan.P

    Hello Sai,
    I am afraid you have posted your question in the wrong forum. This forum is about Oracle On Track Communication, a next-generation social enterprise collaboration product.
    Please re-post your question in an ADF related forum and I am sure someone will be able to answer.
    Thank you,
    Ernst.

  • Focus Lost on Tree Cell Edit

    I am trying to force changes made in a tree cell edit when focus to that tree node has been lost(like on an enter button press) but it always reverts to the old value. i have tried adding a CellEditorListener to force an enter key press on the editingCanceled action but this still reverts the value.
    Anyone have any ideas on how to fix this?
    Thanks.

    Hi,
    Try to use
        call method cl_gui_control=>set_focus exporting control = grid1.

  • Handling tree focus in webdynpro

    Hi All
    I want focus on a particular tree node only on its  selection and no focus on any tree node initially.
    but it always displays the focus on first tree node by default.
    How to handle this?

    Hi Swati,
    You can always navigate to the relevant element on the tree and have it selected by changing the lead selection in the context.
    wdContext.nodeTestNode().currentTestNodeElement().node().setLeadSelection(3);
    Now it should point to the relevant selected element on the tree.
    Regards,
    Arun

  • Question on removing a child node in a tree component - JSF

    When I m trying to delete a child node in a tree component the focus is not transfering to the parent node. I m using the setselected method to set the focus to the current node but not sure how to transfer the focus to parent node once I delete a child node. Please advice.

    Doubleposted: [http://forums.sun.com/thread.jspa?threadID=5389876]. Please stick to one topic or use the edit button.

  • Setting annimated image to tree node

    Hi all,
    I am setting an annimated gif image to tree node like this,
    ImageIcon newIcon = ImageIcon.get("test.gif");
    setClosedIcon(newIcon);
    setOpenIcon(newIcon);
    setLeafIcon(newIcon);
    but with this the annimation effect doesn't appear in the node.
    It is only static image without annimation.
    what is wrong here?
    how to achieve annimation on tree node?
    pls help
    -Soni

    Thanks for the reply Frank.
    I saw the link http://sreevardhanadf.blogspot.in/2012/07/showing-next-row-as-current-row-after.html
    However the issue is since I am using custom created tree using POJO tree item (composite object).
    calling myTree.getWrappedData() doesn't gives me a handle to JUCtrlHierBinding and subsequent access to JUCtrlHierNodeBinding.
    my program gives me data like -
    List<MyTreeItem> treeData = (List<MyTreeItem>)treeModel.getWrappedData();
    because my tree model is build using -
    treeModel = new ChildPropertyTreeModel(items, "children");
    where items is List of <MyTreeItem>
    Hence I am unable to get a handle using -
    List nodeParentList = nodeParent .getKeyPath();
    I am programmatically able to invoke the parent node to get the fresh data, only issue is the focus/selection of that node is not happening
    Is there a way around?
    Thanks
    Sachin

  • Can't get Checkbox selection status in Tree

    Hi,
    I'm using a Checkbox Tree which I got from here: [http://www.java2s.com/Code/Java/Swing-JFC/CheckBoxNodeTreeSample.htm|http://www.java2s.com/Code/Java/Swing-JFC/CheckBoxNodeTreeSample.htm]
    Now, I want to determine whether the Checkboxes are selected or not.
    Unfortunately, the custom CheckBox model class always returns true, which is stored in a Vector.
    In short, this is how the checkTree is created:
    CheckBoxNode tabFormatNode = new CheckBoxNode[]{new CheckBoxNode("GP3", true),
                                        new CheckBoxNode("GP4", true),
                                        new CheckBoxNode("GP5", true)};
    NamedVector formatVector = new NamedVector("Format", tabFormatNode);
    Object[] rootNodes = new Object[]{ formatVector }
    Vector rootVector = new NamedVector("root", rootNodes);
    TreeModel model = createTreeModel(rootVector);
    setModel(model);As I said, when I retrieve a CheckBoxNode from the Vector, it always return true on isSelected(), so that's no use.
    However, the renderer does manage to get the selection status correctly.
    private static class CheckBoxNodeRenderer implements TreeCellRenderer
            private JCheckBox leafRenderer = new JCheckBox();
            protected JCheckBox getLeafRenderer()
                return leafRenderer;
            public CheckBoxNodeRenderer()
            public Component getTreeCellRendererComponent(JTree tree, Object value,
                  boolean selected, boolean expanded, boolean leaf, int row,
                  boolean hasFocus)
                Component returnValue;
                if (leaf)
                    String stringValue = tree.convertValueToText(value, selected,
                        expanded, leaf, row, false);
                    leafRenderer.setText(stringValue);
                    leafRenderer.setSelected(false);
                    if (selected)
                        leafRenderer.setForeground(selectionForeground);
                        leafRenderer.setBackground(selectionBackground);
                    else
                        leafRenderer.setForeground(textForeground);
                        leafRenderer.setBackground(textBackground);
                    if ((value != null) && (value instanceof DefaultMutableTreeNode))
                        Object userObject = ((DefaultMutableTreeNode) value)
                        .getUserObject();
                        if (userObject instanceof CheckBoxNode)
                            CheckBoxNode node = (CheckBoxNode) userObject;
                            leafRenderer.setText(node.getText());
                            leafRenderer.setSelected(node.isSelected());
                            // eigen
                            leafRenderer.setEnabled(Overview.getTabbedPane().getActiveTabList().isLeftPaneEnabled());
                    returnValue = leafRenderer;
                else
                  returnValue = nonLeafRenderer.getTreeCellRendererComponent(tree,
                      value, selected, expanded, leaf, row, hasFocus);
                return returnValue;
        }Could anyone help me with retrieving the correct selection values of the CheckBoxes?
    Edited by: Tails on 21-mrt-2008 13:07

    OK Tails. here are the changes you need, in CheckBoxNodeEditor method getTreeCellEditorComponent. Note that Component editor is now declared as final so that in can be accessed from within the inner class.   public Component getTreeCellEditorComponent (JTree tree, Object value,
             boolean selected, boolean expanded, boolean leaf, int row) {
          // change to final
          final Component editor = renderer.getTreeCellRendererComponent (tree, value,
                true, expanded, leaf, row, true);
          // editor always selected / focused
          // line added
          final CheckBoxNode cbn = (CheckBoxNode) ((DefaultMutableTreeNode) value).getUserObject ();
          ItemListener itemListener = new ItemListener () {
             public void itemStateChanged (ItemEvent itemEvent) {
                // line added
                cbn.setSelected (((CheckBoxNode) getCellEditorValue ()).isSelected ());
                if (stopCellEditing ()) {
                   fireEditingStopped ();
          if (editor instanceof JCheckBox) {
             ((JCheckBox) editor).addItemListener (itemListener);
          return editor;
       }Get back to us on whether that solves the problem, willya.
    db

Maybe you are looking for