Tree node color

Last resort here. Calling all hands on deck. I want to be
able to search my tree for anything that starts with AOL and expand
the tree and color/bold/ anything to the node that meets the
requirements. I have all of it working except for the coloring
part. This(of course) does not work. But maybe something along this
thought process:
[email protected] = "red";
myXML.node.@label Gets the tree nodes just fine, I just don't
know how to color the text. Any help or push, maybe a kick in the
right direction would be appreciated.

Anything?

Similar Messages

  • How to highlight Tree node with a diff color

    I have created tree node and want to highlight Selected node with a different background color. Any Ideas how can we achieve that? -R

    It's an item on page 4 of the application that the blog example is taken from. The tree query:
    SELECT EMPLOYEE_ID AS ID
         , MANAGER_ID  AS PID
         , CASE
             WHEN EMPLOYEE_ID = :P4_EMPLOYEE_ID THEN
                 '<span style="color:white;background-color:blue;">'||
                 LAST_NAME||
                 '</span>'
             ELSE
                 LAST_NAME
           END AS NAME
         , 'f?p=&APP_ID.:4:'||:SESSION||'::NO::P4_EMPLOYEE_ID:'||EMPLOYEE_ID AS LINK
         , NULL        AS A1
         , NULL        AS A2
      FROM #OWNER#.EMPLOYEESgenerates leaf nodes that link to page 4, setting the value of P4_EMPLOYEE_ID. When page 4 is rendered, P4_EMPLOYEE_ID contains the ID of the clicked node, the page displays details of the employee with this ID, and the case expression in the tree query causes the corresponding display value to be highlighted.
    See the sections Managing Session State Values and Using f?p Syntax to Link Pages in the documentation to understand how to set session state values using URLs.
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/concept.htm

  • How to resize a custom tree node like you would a JFrame window?

    Hello,
    I am trying to resize a custom tree node like you would a JFrame window.
    As with a JFrame, when your mouse crosses the Border, the cursor should change and you are able to drag the edge to resize the node.
    However, I am faced with a problem. Border cannot detect this and I dont want to use a mouse motion listener (with a large number of nodes, I fear it will be inefficient, calculating every node's position constantly).
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Insets;
    import java.util.EventObject;
    import javax.swing.BorderFactory;
    import javax.swing.Box;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellEditor;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeSelectionModel;
    public class ResizeNode extends JPanel {
           AnilTreeCellRenderer2 atcr;
           AnilTreeCellEditor2 atce;
           DefaultTreeModel treeModel;
           JTree tree;
           DefaultMutableTreeNode markedNode = null;
         public ResizeNode() {
                super(new BorderLayout());
                   treeModel = new DefaultTreeModel(null);
                   tree = new JTree(treeModel);          
                  tree.setEditable(true);
                   tree.getSelectionModel().setSelectionMode(
                             TreeSelectionModel.SINGLE_TREE_SELECTION);
                   tree.setShowsRootHandles(true);
                  tree.setCellRenderer(atcr = new AnilTreeCellRenderer2());
                  tree.setCellEditor(atce = new AnilTreeCellEditor2(tree, atcr));
                   JScrollPane scrollPane = new JScrollPane(tree);
                   add(scrollPane,BorderLayout.CENTER);
         public void setRootNode(DefaultMutableTreeNode node) {
              treeModel.setRoot(node);
              treeModel.reload();
           public static void main(String[] args){
                ResizeNode tb = new ResizeNode();
                tb.setPreferredSize(new Dimension(400,200));
                  JFrame frame = new JFrame("ResizeNode");
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setContentPane(tb);
                  frame.setSize(400, 200);
                  frame.pack();
                  frame.setVisible(true);
                  tb.populate();
         private void populate() {
              TextAreaNode2 r = new TextAreaNode2(this);
               setRootNode(r);
               TextAreaNode2 a = new TextAreaNode2(this);
               treeModel.insertNodeInto(a, r, r.getChildCount());          
    class AnilTreeCellRenderer2 extends DefaultTreeCellRenderer{
    TreeBasic panel;
    DefaultMutableTreeNode currentNode;
      public AnilTreeCellRenderer2() {
         super();
    public Component getTreeCellRendererComponent
       (JTree tree, Object value, boolean selected, boolean expanded,
       boolean leaf, int row, boolean hasFocus){
         TextAreaNode2 currentNode = (TextAreaNode2)value;
         NodeGUI2 gNode = (NodeGUI2) currentNode.gNode;
        return gNode.box;
    class AnilTreeCellEditor2 extends DefaultTreeCellEditor{
      DefaultTreeCellRenderer rend;
      public AnilTreeCellEditor2(JTree tree, DefaultTreeCellRenderer r){
        super(tree, r);
        rend = r;
      public Component getTreeCellEditorComponent(JTree tree, Object value,
       boolean isSelected, boolean expanded, boolean leaf, int row){
        return rend.getTreeCellRendererComponent(tree, value, isSelected, expanded,
         leaf, row, true);
      public boolean isCellEditable(EventObject event){
        return true;
    class NodeGUI2 {
         final ResizeNode view;
         Box box = Box.createVerticalBox();
         final JTextArea aa = new JTextArea( 1, 5 );
         final JTextArea aaa = new JTextArea( 1, 8 );
         NodeGUI2( ResizeNode view_ ) {
              this.view = view_;
              box.add( aa );
              aa.setBorder( BorderFactory.createMatteBorder( 0, 0, 1, 0, Color.GREEN ) );
              box.add( aaa );
              box.setBorder( BorderFactory.createMatteBorder( 5, 5, 5, 5, Color.CYAN ) );
         private Dimension getEditorPreferredSize() {
              Insets insets = box.getInsets();
              Dimension boxSize = box.getPreferredSize();
              Dimension aaSize = aa.getPreferredSize();
              Dimension aaaSize = aaa.getPreferredSize();
              int height = aaSize.height + aaaSize.height + insets.top + insets.bottom;
              int width = Math.max( aaSize.width, aaaSize.width );
              if ( width < boxSize.width )
                   width += insets.right + insets.left + 3;     // 3 for cursor
              return new Dimension( width, height );               
    class TextAreaNode2 extends DefaultMutableTreeNode {  
         NodeGUI2 gNode;
         TextAreaNode2(ResizeNode view_) {     
              gNode = new NodeGUI2(view_);
    }

    the node on the tree is only painted on using the
    renderer to do the painting work. A mouse listener
    has to be added to the tree, and when moved over an
    area, you have to determine if you are over the
    border and which direction to update the cursor and
    to know which way to resize when dragged. One of the
    BasicRootPaneUI has some code that can help determine
    that.Thanks for replying. What is your opinion on this alternative idea that I just had?
    I am wondering if it might be easier to have a toggle button in the node that you click when you want to resize the node. Then a mouse-down and dragging the mouse will resize the node. Mouse-up will reset the toggle button, and so will mouse down in an invalid area.
    Anil

  • JTree - Fetch URL from a tree node.

    Now I have created one JTree and one JEditorPane.
    Basically I am creating a help file. (a chm file in windows).
    So I need to handle mouse click event on each node on JTree.
    I have used such format to add a hyperlink.
    sample code:---------------------------------------------------------------------------------------------------------------------------
    javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("JTree");
    javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("colors");
    javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("blue");
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("violet");
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("red");
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("yellow");
    treeNode2.add(treeNode3);
    treeNode1.add(treeNode2);
    treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("s");
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("<html><a href='C:\\Program Files\\Java\\jdk1.6\\README.html'>Read Me</a></html>");
    treeNode2.add(treeNode3);
    jTree1.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
    jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mousePressed(java.awt.event.MouseEvent evt) {
    TreeListener(evt);
    private void TreeListener(java.awt.event.MouseEvent evt) {                                    
    int selRow= jTree1.getRowForLocation(evt.getX(), evt.getY());
    TreePath tp = jTree1.getPathForLocation(evt.getX(), evt.getY());
    if(selRow!=-1) {
    if(evt.getClickCount()==1) {              
    jTree1.setSelectionPath(tp);
    Now there is a hyperlink created for that node "Read Me".
    My Question is ..........
    How do I fetch this stored URL in each node for setting it to my JEditorPane....???

    ok, it seems to be working now. I just return the JInternalFrame in the getTreeCellRendererComponent() method.

  • JTree Node Color, to distinguish between different activities

    Hi,
    Situation:          Dynamic JTree (Tree is constructed from as a result of Database). User has the option to either Enable / Disable node and can repeat the activities but restricted only one activity per node, the node is to be highlighted; to restrict the user from further activities.
    Problem:          Am a newbie to swing, after searching the forum for the same, i found few good solutions which are specific to color change of specific selected node, in a temporary context.
         But we need the node color change within a same level; to distinguish either the node is either enabled / disabled.
    Your help is appreciated,

    durino13 wrote:
    1. Is the approach above a good approach, how to load children 'lazilly'?Sounds pretty reasonable to me.
    2. I also use custom renderer to display different icons for every "tree" level. When I initially expand the 4th level, everything works fine !!! Then I collapse the 4th level and expand it again and here my problem starts: my 4th level icon is set to 'root level icon' instead of '4th level' icon. This does not happen, if computerNode.removeAllChildren(); method is removed from listening above
    Any idea, what am i doing wrong?Ummmm... Load the model the first time (only) the node is expanded... Putz!
    And I suggest you listen deeply to Mr Jacobs... He really does know what he's talking about ;-)
    ... and not this time, but in future: Swing questions are best asked in [THE Swing Forum|http://forums.sun.com/forum.jspa?forumID=57].
    Cheers. Keith.

  • Is it possible to change TreeView's background color, not node color?

    In advance, Thanks!!
    Actually, I've made my own treeview in my project. and  I've changed my treeview node color as i want
    I wonder whether or not to change treeview's background color, not node color in below class.
    // in ~.fr
    Class
      kMyTreeViewWidgetBoss,
      kTreeViewWidgetBoss,
         IID_ICONTROLVIEW,                    kMyTreeViewCtrlViewImpl,  
         IID_ITREEVIEWWIDGETMGR,      kMyTreeViewListBoxWidgetMgrImpl,
         IID_ITREEVIEWHIERARCHYADAPTER,  kMyTreeViewListBoxHierarchyAdapterImpl,
         IID_ISTRINGLISTDATA,                          kStringListDataImpl,
         IID_IOBSERVER,                                  kMyTreeViewCtrlBoxObserverImpl,
    type MainTreeViewListBox(kViewRsrcType)       : TreeViewWidget    (ClassID = kMyTreeViewWidgetBoss)  {};
    MainTreeViewListBox   //Tree view
               kMyTreeViewWithTextListWidgetID, kPMRsrcID_None, // WidgetId, RsrcId
               kBindAll,           // Frame binding
               Frame(-1, 26, 300, 276)  // Frame
               kTrue, kTrue,         // Visible, Enabled
               kTrue,       // EraseBeforeDraw
               kInterfacePaletteFill,   // InterfaceColor
               kHideRootNode,// | kDrawEndLine, // Options. Display root node
               kFalse,  // Use H Scroll bar
               kTrue,  // Use V scroll bar
               20,   // fVScrollButtonIncrement
               20,   // fVThumbScrollIncrement
               0,   // fHScrollButtonIncrement
               0,   // fHThumbScrollIncrement
               2,   // Items selectable, 0 = No Selection, 1 = Single Selection, 2 = Multiple Selection
               kFalse,  // Allow children from multiple parents to be selected
               kTrue,  // Allow discontiguous selection
                //The tree view is dynamically created. 
    class MyTreeViewCtrlView : public PanelView
    virtual void   Draw(IViewPort* viewPort, SysRgn updateRgn);
    void MyTreeViewCtrlView::Draw( IViewPort*  viewPort, SysRgn  updateRgn )
       AGMGraphicsContext gc(viewPort, this, updateRgn);
      InterfacePtr<IGraphicsPort>  gPort(gc.GetViewPort(), UseDefaultIID()); // IID_IGRAPHICSPORT);
      ASSERT(gPort);
      gPort->gsave();
      PMRect frameOut      = GetFrame();
      frameOut.MoveTo(0, 0);
      COLORREF crBackColor    = RGB( 255, 0, 0 );
      gPort->setrgbcolor( GetRGBtoReal( GetRValue(crBackColor) ), GetRGBtoReal( GetGValue(crBackColor) ), GetRGBtoReal( GetBValue (crBackColor) ));
    gPort->rectpath(frameOut);
    gPort->fill();
    gPort->grestore();
    PanelView::Draw( viewPort, updateRgn );
    In above case, there are errors in kMyTreeViewCtrlViewImple when Indesign is launching.
    // Error Assert
    XferObject- ReadWrite for impl kMyTreeViewCtrlViewImpl of iid IID_ICONTROLVIEW in class kMyTreeViewWidgetBoss read wrong amount in plugin kMyTreeViewWidgetBoss
    but, in kMyTreeViewWidgetBoss ClassDescriptionTable, when remove this( IID_ICONTROLVIEW, kMyTreeViewCtrlViewImpl), that's ok. but I can't change background color. just interfacepalettefill color
    Please help me!!

    Here's a sample!
    That's all.
    #define GetRGBtoReal( X )   (double) X / (double) 255.f
    COLORREF crBackColor    = RGB( 255, 0, 0 );
    gPort->setrgbcolor( GetRGBtoReal( GetRValue(crBackColor) ), GetRGBtoReal( GetGValue(crBackColor) ), GetRGBtoReal( GetBValue(crBackColor) ));

  • TREE NODE IN F4 SEARCH HELP

    Hi All,
    Can anyone help me to implement Tree node in F4 Search help?
    Thanks
    E Karthikeyan

    SAP has provided a lot of sample programs for developing tree structures. Just go to SE38, type BCALVTREE and hit F4. You'll get different sample programs with a range of operations on trees
    Go through the link,
    http://www.sapdevelopment.co.uk/reporting/alv/alvtree.htm
    Slowly check this code..you will get idea of how to develop tree structure.
    REPORT y_hierarchies_in_tables
    NO STANDARD PAGE HEADING.
    PARAMETER: g_group TYPE grpname. " DEFAULT 'Z_GLAB0000'.
    DATA:
    g_setid TYPE setid,
    g_class TYPE setclass.
    DATA: lt_hier TYPE STANDARD TABLE OF sethier,
    lt_val TYPE STANDARD TABLE OF setvalues.
    DATA: hier LIKE sethier OCCURS 0 WITH HEADER LINE,
    val LIKE setvalues OCCURS 0 WITH HEADER LINE,
    setinfo LIKE setinfo OCCURS 0 WITH HEADER LINE.
    DATA: zaccbas(20) TYPE c OCCURS 0 WITH HEADER LINE.
    DATA: miss_val LIKE setvalues-from OCCURS 0 WITH HEADER LINE.
    DATA: table_name TYPE tabname,
    field_name TYPE setfld.
    DATA: ambiguity_flag TYPE c.
    Ambiguity check
    PERFORM ambiguity_check.
    Display Records
    PERFORM display_records.
    *& Form AMBIGUITY_CHECK
    Ambiguity check
    FORM ambiguity_check .
    DATA: it_abaplist LIKE abaplist OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF it_ascilist OCCURS 0,
    zeile(256) TYPE c,
    END OF it_ascilist.
    DATA: flag.
    SUBMIT rgsovl00 "VIA SELECTION-SCREEN
    WITH p_shrtn = g_group
    WITH path = 'X'
    EXPORTING LIST TO MEMORY
    AND RETURN.
    CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
    listobject = it_abaplist
    EXCEPTIONS
    not_found = 1
    OTHERS = 2.
    CALL FUNCTION 'LIST_TO_ASCI'
    TABLES
    listasci = it_ascilist
    listobject = it_abaplist
    EXCEPTIONS
    empty_list = 1
    list_index_invalid = 2
    OTHERS = 3 .
    LOOP AT it_ascilist.
    IF it_ascilist-zeile = text-001.
    flag = 'X'.
    ENDIF.
    IF flag = 'X' AND
    it_ascilist-zeile = text-002.
    ambiguity_flag = 'X'.
    CLEAR flag.
    ENDIF.
    ENDLOOP.
    FREE MEMORY.
    ENDFORM. " AMBIGUITY_CHECK
    *& Form DISPLAY_RECORDS
    Display the Records
    FORM display_records .
    PERFORM get_records.
    PERFORM header_data.
    PERFORM item_data.
    ENDFORM. " DISPLAY_RECORDS
    *& Form GET_RECORDS
    Get all the Node values
    FORM get_records .
    Get the ID name for the Hierarchy
    CALL FUNCTION 'G_SET_GET_ID_FROM_NAME'
    EXPORTING
    shortname = g_group
    setclass = g_class
    old_setid = g_setid
    IMPORTING
    new_setid = g_setid.
    Get the Table and Field name for the Top Node
    CALL FUNCTION 'G_SET_GET_INFO'
    EXPORTING
    setname = g_setid
    no_set_title = 'X'
    use_table_buffer = 'X'
    IMPORTING
    info = setinfo.
    table_name = setinfo-tabname.
    field_name = setinfo-fld.
    Get all the Nodes for the Hierarchy
    CALL FUNCTION 'G_SET_TREE_IMPORT'
    EXPORTING
    no_descriptions = ' '
    no_rw_info = 'X'
    setid = g_setid
    TABLES
    set_hierarchy = lt_hier
    set_values = lt_val.
    hier[] = lt_hier.
    val[] = lt_val.
    SELECT (field_name) FROM (table_name) INTO TABLE zaccbas.
    LOOP AT zaccbas.
    READ TABLE val WITH KEY FROM = zaccbas.
    IF sy-subrc = 0.
    DELETE zaccbas.
    CLEAR zaccbas.
    DELETE val INDEX sy-tabix.
    CLEAR val.
    ENDIF.
    ENDLOOP.
    ENDFORM. " GET_RECORDS
    *& Form HEADER_DATA
    Header Data
    FORM header_data .
    DATA: desc TYPE settext.
    READ TABLE hier WITH KEY fieldname = field_name
    shortname = g_group.
    IF sy-subrc = 0.
    desc = hier-descript.
    ENDIF.
    SKIP.
    WRITE: 'Node :',g_group.
    WRITE:75 'User name :', sy-uname.
    WRITE:/ 'Description :', desc.
    WRITE:75 'Date:', sy-datum.
    WRITE:/ 'Table Name :' , table_name.
    WRITE:75 'Time:', sy-timlo.
    WRITE:/ 'Field Name :', field_name.
    write:75 'Client:', SY-MANDT.
    skip.
    IF ambiguity_flag = 'X'.
    WRITE:/ 'Ambiguity Check :'. WRITE: 'Success' COLOR 5.
    ELSE.
    WRITE:/ 'Ambiguity Check :'. WRITE: 'Failed' COLOR 6 .
    ENDIF.
    WRITE:/ sy-uline.
    WRITE:/37 'Validation for Hierarchy'.
    WRITE:/ sy-uline.
    ENDFORM. " HEADER_DATA
    *& Form ITEM_DATA
    Output Report for Nodes
    FORM item_data .
    IF NOT zaccbas[] IS INITIAL.
    WRITE:/ 'Missing Records from Hierarchy' COLOR 3.
    LOOP AT zaccbas.
    WRITE:/ zaccbas.
    ENDLOOP.
    ENDIF.
    IF NOT val[] IS INITIAL.
    SKIP 1.
    WRITE:/ 'Additional Records in Hierarchy' COLOR 3.
    LOOP AT val.
    WRITE:/ val-from. ", 28 val-DESCRIPT.
    ENDLOOP.
    ELSEIF ZACCBAS[] IS INITIAL.
    WRITE:/ 'No Missing Records Found' COLOR 3.
    ENDIF.
    ENDFORM. " ITEM_DATA
    Thanks,
    Sakthi C
    *Rewards if useful*

  • Swap Tree Nodes

    Want to swap tree nodes. Please run the sample below where I need the help in the print statements. Five duke dollars from http://forum.java.sun.com/thread.jsp?forum=43&thread=431639
    Thanks
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    public class TreeExample extends JFrame implements ActionListener {
       private static final int WIDTH = 640;
       private static final int HEIGHT = 480;
       private static final String MOVE_UP_ACTION = "move_up_action";
       private static final String MOVE_DOWN_ACTION = "move_down_action";
       private JTree tree = null;
       public TreeExample() {
          super("Wizard test");
          Container container = getContentPane();
          container.setLayout(new BorderLayout());
          int locX = (Toolkit.getDefaultToolkit().getScreenSize().width - WIDTH) / 2;
          int locY = (Toolkit.getDefaultToolkit().getScreenSize().height - HEIGHT) / 2;
          setBounds(locX, locY, WIDTH, HEIGHT);
          addWindowListener(new WindowAdapter() {
             public void windowClosing( WindowEvent e ) {
                System.exit(0);
          JPanel buttonsPanel = new JPanel();
          buttonsPanel.setLayout(new GridLayout(2, 1, 0, 8));
          final JButton moveUpButton = new JButton("Move Up");
          moveUpButton.setFont(moveUpButton.getFont().deriveFont(Font.PLAIN));
          moveUpButton.setMnemonic('U');
          moveUpButton.setActionCommand(MOVE_UP_ACTION);
          moveUpButton.setEnabled(false);
          moveUpButton.addActionListener(this);
          final JButton moveDownButton = new JButton("Move Down");
          moveDownButton.setFont(moveUpButton.getFont().deriveFont(Font.PLAIN));
          moveDownButton.setMnemonic('D');
          moveDownButton.setActionCommand(MOVE_DOWN_ACTION);
          moveDownButton.setEnabled(false);
          moveDownButton.addActionListener(this);
          buttonsPanel.add(moveUpButton);
          buttonsPanel.add(moveDownButton);
          /*************** Create accounts tree table and buttons panel on the right of it **************/
          DefaultMutableTreeNode root = new DefaultMutableTreeNode("Sample");
          DefaultMutableTreeNode colors = new DefaultMutableTreeNode("colors");
          colors.add(new DefaultMutableTreeNode("blue"));
          colors.add(new DefaultMutableTreeNode("violet"));
          colors.add(new DefaultMutableTreeNode("red"));
          colors.add(new DefaultMutableTreeNode("yellow"));
          DefaultMutableTreeNode sports = new DefaultMutableTreeNode("sports");
          sports.add(new DefaultMutableTreeNode("basketball"));
          sports.add(new DefaultMutableTreeNode("soccer"));
          sports.add(new DefaultMutableTreeNode("football"));
          sports.add(new DefaultMutableTreeNode("hockey"));
          DefaultMutableTreeNode programs = new DefaultMutableTreeNode("programs");
          programs.add(new DefaultMutableTreeNode("Java"));
          programs.add(new DefaultMutableTreeNode("ASP .Net"));
          programs.add(new DefaultMutableTreeNode("C"));
          programs.add(new DefaultMutableTreeNode("Perl"));
          root.add(colors);
          root.add(sports);
          root.add(programs);
          tree = new JTree(root);   
          tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
          tree.addTreeSelectionListener(new TreeSelectionListener() {
             public void valueChanged(TreeSelectionEvent e) {
                Object nodeInfo = tree.getLastSelectedPathComponent();
                if (nodeInfo == null) return;
                DefaultMutableTreeNode treeSelectNode = (DefaultMutableTreeNode) nodeInfo;
                DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) treeSelectNode.getParent();
                if (parentNode != null) {
                   moveUpButton.setEnabled(parentNode.getChildCount() > 1 &&
                                          !parentNode.getFirstChild().equals(treeSelectNode));
                   moveDownButton.setEnabled(parentNode.getChildCount() > 1 &&
                                            !parentNode.getLastChild().equals(treeSelectNode));
                else {
                   moveDownButton.setEnabled(false);
                   moveUpButton.setEnabled(false);
          JScrollPane scrollPane = new JScrollPane(tree);
          JPanel mainPanel = new JPanel();
          mainPanel.setLayout(new GridBagLayout());
          constrain( mainPanel, scrollPane,
                     GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST,
                     0, 0, 1, 1, 1.0, 1.0, new Insets(10, 10, 10, 10));
          constrain( mainPanel, buttonsPanel,
                     GridBagConstraints.NONE, GridBagConstraints.NORTHWEST,
                     1, 0, 1, 1, 0.0, 0.0, new Insets(10, 0, 10, 10));    
          container.add(mainPanel, BorderLayout.NORTH);
       public void constrain( Container container, Component component, 
                              int fill, int anchor,
                              int gx, int gy, int gw, int gh, double wx, double wy ) {
          GridBagConstraints c = new GridBagConstraints();
          c.fill = fill;
          c.anchor = anchor;
          c.gridx = gx;
          c.gridy = gy;
          c.gridwidth = gw;
          c.gridheight = gh;
          c.weightx = wx;
          c.weighty = wy;
          ( (GridBagLayout) container.getLayout() ).setConstraints( component, c );
          container.add( component );
       public void constrain( Container container, Component component, 
                              int fill, int anchor,
                              int gx, int gy, int gw, int gh,
                              double wx, double wy, Insets inset ) {
          GridBagConstraints c = new GridBagConstraints();
          c.fill = fill;
          c.anchor = anchor;
          c.gridx = gx;
          c.gridy = gy;
          c.gridwidth = gw;
          c.gridheight = gh;
          c.weightx = wx;
          c.weighty = wy;
          c.insets = inset;
          ( (GridBagLayout) container.getLayout() ).setConstraints( component, c );
          container.add( component );
       public void actionPerformed(ActionEvent e) {
          String action = e.getActionCommand();
          Object nodeInfo = tree.getLastSelectedPathComponent();
          if (action != null && nodeInfo != null) {
             DefaultMutableTreeNode treeSelectNode = (DefaultMutableTreeNode) nodeInfo;
             DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) treeSelectNode.getParent();
             if (parentNode != null) {
                int treeSelectIndex = parentNode.getIndex(treeSelectNode);
                if (action.equals(MOVE_UP_ACTION)) {
                   DefaultMutableTreeNode nextNodeUp = (DefaultMutableTreeNode) parentNode.getChildAt(treeSelectIndex - 1);
                   System.out.println("Want to swap " + treeSelectNode + " with " + nextNodeUp);
                if (action.equals(MOVE_DOWN_ACTION)) {
                   DefaultMutableTreeNode nextNodeDown = (DefaultMutableTreeNode) parentNode.getChildAt(treeSelectIndex + 1);
                   System.out.println("Want to swap " + treeSelectNode + " with " + nextNodeDown);          
       public static void main(String args[]) {
          new TreeExample().setVisible(true);

    Hi,
    These the code you want to put in your MOVE_UP and MOVE_DOWN action:
    if (action.equals(MOVE_UP_ACTION))
    DefaultMutableTreeNode nextNodeUp = (DefaultMutableTreeNode) parentNode.getChildAt(treeSelectIndex - 1);
    DefaultTreeModel jTreeModel = (DefaultTreeModel) tree.getModel();
    jTreeModel.insertNodeInto (treeSelectNode, parentNode, treeSelectIndex-1);
    jTreeModel.insertNodeInto (nextNodeUp, parentNode, treeSelectIndex);
    jTreeModel.nodeChanged(parentNode);
    jTreeModel.reload(parentNode);
    TreePath treePath = new TreePath(jTreeModel.getPathToRoot(treeSelectNode));
    tree.setSelectionPath(treePath);
    if (action.equals(MOVE_DOWN_ACTION))
    DefaultMutableTreeNode nextNodeDown = (DefaultMutableTreeNode) parentNode.getChildAt(treeSelectIndex + 1);
    DefaultTreeModel jTreeModel = (DefaultTreeModel) tree.getModel();
    jTreeModel.insertNodeInto (treeSelectNode, parentNode, treeSelectIndex+1);
    jTreeModel.insertNodeInto (nextNodeDown, parentNode, treeSelectIndex);
    jTreeModel.nodeChanged(parentNode);
    jTreeModel.reload(parentNode);
    TreePath treePath = new TreePath(jTreeModel.getPathToRoot(treeSelectNode));
    tree.setSelectionPath(treePath);
    Hope this help,
    Diego.

  • How to display the tree nodes distinctivly.

    Hay all,
    Frnds , i am facing a problem. I have created a tree whose each node consisted of a checkbox and a label. For that i have used DefaultMutableTreeNodes for tree nodes and a TreeCellRenderer. Is there any method or way to display some nodes distinctively(may be in different color or something else). Plz tell me soon its very urgent.

    Hi Jürgen,
    See http://help.sap.com/saphelp_nw04/helpdata/en/44/6aaf92f5a23672e10000000a114a6b/frameset.htm
    Only Worksets and Roles are not described, anyhow, doing a bit research via decompiling or just by searching on SDN will bring you the needed extra info; just as an example for roles access: https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6112ecb7-0a01-0010-ef90-941c70c9e401
    Hope it helps
    Detlev

  • Determine if mouse is over tree node

    hi.
    I recently added some code from this forum on
    highlighting a node when the mouse is over it.
    I am taking this futher and setting a Border around the nodehowever it draws a border around every node.
    I want to only draw the border when the mouse is over the node.
    the example i got does this to set the foreground
    ((JLabel)result).setForeground(Color.red);
    i do this to set the border
    ((JLabel)result).setBorder
    (BorderFactory.createLineBorder(Color.black));
    i ve tried getting the positions of both the mouse and the jlabel but am having trouble determining if the position of the mouse is within the position of the node in the tree.
    Ive used methods like the contains method but it doesnt work for me . can anyone give me a hint as to how to see if the points of the mouse are on the Jlabel?

    This is very close to your solution. Last month, I implement ToolTip Text on every Tree Node so when Mouse goes on to the Node, It shows the Tool Tip Text. Have a look at this code and try to change it accordingly.
    This code is in the Constructor in your class.
    tree.setCellRenderer(new IDETreeCellRenderer());
    tree.setToolTipText("");Class: IDETreeCellRenderer - Cell Renderer for the Tree
    package tv.izone.ide.tree;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import tv.izone.core.*;
    import tv.izone.ide.guiutilities.*;
    import tv.izone.izml.data.*;
    public class IDETreeCellRenderer
        extends DefaultTreeCellRenderer {
       DefaultTreeCellRenderer label;
        * Override TreeCellRendererComponent, used for changing Tree Node for comments.
        * @param tree Tree to be used
        * @param value Value of the Node
        * @param selected true, if selected
        * @param expanded true, if expanded
        * @param leaf true, if it is a leaf
        * @param row Row Number
        * @param hasFocus True, if has Focus
        * @return Component, Tree
       public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
                                      boolean leaf, int row, boolean hasFocus) {
          try {
          label = (DefaultTreeCellRenderer)super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
                                                      hasFocus);
          label.setToolTipText(dataObject.getToolTipText());
    // Instead of setToolTipText(), try setBackgroundColor() or setBorder()
         return label;
          } catch (Exception ex) {
          // NullPointerException, usually comes at the start of the Application
          // when the Tree is empty.
          return this;
    }Hope this Helps
    Regards
    Raheel

  • Af:tree - how do I highlight the selected tree node?

    af:tree
    I checked the generated CSS file. I found that when a tree node is selected, the related CSS attribute is:
    .xj:link{
    font-family:Arial,Helvetica,Geneva,sans-serif;
    font-size:10pt;
    font-weight:normal;
    color:#663300
    I created a customized CSS attribute, but then all of the links have the customized CSS attributes.
    How do I just highlight the selected tree node link?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    try doing the onclick javascript method
    you have to place it on the node element and id must be made dynamic
    for this use 'this.id'
    by which the current id of the node is passed
    and by capturing the id name in a var
    use the same for invoking its selected property and make it true
    like this
    var currentid = this.id;
    this.form.currentid.selected = true;

  • Urgent please respond... JTree Speceific Node Coloring

    hi
    i am facing a problem.I want to create root node with different color anf font and its child node with different color and font.When I change the color of my tree the whole tree nodes are given the same color.Is there any way in which i can color different nodes in the tree with different colors and font?

    Use TreeCellRenderer
    "javax.swing.tree.TreeCellRenderer"

  • Tree Nodes has White Outline/Border

    Hi,
    I'm using an ADF tree located inside a panelGroupLayout.
    The panelGroupLayout has the background color "light blue".
    At runtime each tree node is displayed with a surrounding white outline and that can only appear when you have a background color different than white (in my case the panelGroupLayout is "light blue").
    Does anybody knows how to remove that outline? or to change its color?
    Thanks,
    Alain.

    Here are the skin seletors
    tr:tree Component
    Icon Selectors
    Name      Description
    af|tree::expanded-icon      This icon is displayed before the expanded tree node.
    af|tree::collapsed-icon      This icon is displayed before the collapsed tree node.
    af|tree::no-children-icon      This icon is displayed instead of the expanded/collapsed icon, when the node has no children
    af|tree::line-icon      This icon is used as a vertical line between the nodes.
    af|tree::line-middle-icon      This icon is used as the horizontal line in the background of the expand/collapse icon of the node, in the case the node is not the last sibling of its parent node.
    af|tree::line-last-icon      This icon is used as the horizontal line in the background of the expand/collapse icon of the node, in the case the node is the last sibling of its parent node.
    af|tree::node-icon      This icon selector is used in the case the Node class has a getNodeType() method that returns the node type as string. The nodetype gets added to this selector, separated by a ':'. If the node is a container (has children) the following suffixes get added depending on the expanded/collapsed state: '-expanded' / '-collapsed'. e.g. "af|tree::node-icon:container-collapsed", "af|tree::node-icon:container-expanded", "af|tree::node-icon:noncontainer".
    Trinidad properties
    Name      Description
    -tr-show-lines      Valid values are true or false (default true). Determines whether the tree lines are displayed or not. e.g., af|tree {-tr-show-lines:false} will not show the lines of the tree.Timo

  • Change the Node Color

    how do i change the Node color in the JTree

    What do you mean it doesn't help you? PhHein told you you need to use TreeCellRenderer and gave you a link to a tutorial, what more do you want? You need to create a class that implements TreeCellRenderer like:
    private static class CellRenderer implements TreeCellRendererAnd implement this method:
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
      boolean expanded, boolean leaf, int row, boolean hasFocus)If you want to be spoon fed, you need to pay for a tutor.

  • Apex Tree Node Search

    Hi guys,
    I want to search a tree node by using a textbox and a button item. I have implemented all required items and regions into my page. I think that, i can do this by using dynamic action. So I wrote a small script (jquery) to use in dynamic action in button click event. It gets the value of the textbox item and tries to use this value in tree's search method. By the way I specified a static ID for my tree region. (As you can see it is TREEID). But it doesn't work. Maybe usage of the method is different.
    So ,
    1 : The method usage is right?
    2 : Do you have any other idea about how can i do this search stuff.
    $("#TREEID").tree("search", document.getElementById("P300_SEARCH_TEXT").value);
    Database : Oracle11g
    Apex version : 4.1
    Thanks

    Mimi gave a very good start though. I have not worked with a tree before, but those tips guided me to the documentation, and i was able to take it from there. I can't see how the documentation would be lacking for you though, i find it to be clear. However, if you don't have some experience with javascript/jquery, this will not be straightforward.
    I made a new tree page, based this on EMP.
    When you want to do a search, you will first need the tree object, since the search function is a function of that object. I opened Firebug and ran this in my console:
    jQuery.tree.focused()This is in the docs. "This functions returns the currently focused tree instance."
    If you would have more trees, you could always use
    jQuery.tree.reference(needle)This functions returns a specific tree instance by an ID or contained node.
    Arguments:
    mixed needle
    This can be either the instance ID (the ID of the container node), an ID of any contained DOM element,
    an actual DOM element contained within the tree, or a jQuery extended DOM node container within the tree.>
    Now you have your tree object. Let's do a search. There are 2 employees with 'LL' in their names. I want to grab those.
    $.tree.focused().search("LL")This'll do "nothing". Why? Take a look at the documentation:
    Searches all nodes whose titles match a given string. If async is used a request is made to the server, the response should contain the comma-separated IDs of nodes that need to be opened so that all nodes that match the search string are visible.
    The search string is provided in the request. The function triggers the onsearch callback, with the nodes found as a parameter.
    Arguments:
    string needle
    The search string.
    string compare_function
    Optional argument. The jQuery function to be used for comparing titles to the string - defaults to "contains".>
    What is of importance here is this: The function triggers the onsearch callback
    +(oh, and please note that the search is looking for a match in the TITLE of the nodes!)+
    So, taking a look at onsearch:
    callback.onsearch Triggered after a search is performed and results are ready.
    Receives two parameters - a jQuery collection of nodes matching the search and a reference to the tree instance.
    *Default is: function(NODES, TREE_OBJ) { NODES.addClass("search");* }
    >
    So the default action of a search is something very simple: it assigns a class to the nodes which match the search criteria.
    If you would want more complex things to happen, you can simply provide another function to the tree object for the onsearch callback, and that is what Mimi meant with changing it. But you don't have to if the class-adding is sufficient.
    So, running from my firebug console:
    $(".search").css({"background-color":"red"})Grab all elements with class 'search', and give them a red background color. My nodes are now red for "ALLEN" and "MILLER".
    It also helps to use something like firebug, have knowledge of jquery, DOM and being able to inspect it, and read docs. I did not do anything special except applying some knowledge and taking my lead from those docs. Of course, Mimi mentioned this aswell, but the docs are at *\apex_images\libraries\jquery-jstree\0.9.9a2\documentation.html*
    Hope that helps you forward.

Maybe you are looking for

  • Multiple sessions in a single database connection.

    I have copied the following text from Forms Developer2000 "At runtime, Form Builder automatically establishes and manages a single connection to ORACLE. By default, one user session is created for this connection. However, the multiple-sessioning fea

  • Reporting Services 2012 - "Database is up to date, but some sites are not completely upgraded"

    Running SharePoint 2010 SP1 (Feb-Mar 2012 CU) Is there any official word from Microsoft regarding the issue with SQL Server Reporting Services 2012 for SharePoint where 2 of the reporting service application databases show "Database is up to date, bu

  • How to insert a streaming audio file/link into a basic HTML page?

    I am a novice webmaster managing the website for our arts organization.  I am trying to build a simple table on a page of our site that will have about 30 streaming MP3 audio clips for our members to review.  I'm using Amazon CloudFront and Amazon S3

  • How do terminate a wait condition in a loop?

    I have a while loop that uses a Wait.vi to set the timing. When I terminate the loop, it waits for the next iteration of the "wait" to complete. How can I terminate the wait in the middle of an iteration?

  • How to add estimated additional charges to PO lines

    Hi all, As a business need I want to add estimated additional charges to PO lines like bank expenses, transportation and misc duties. it was available with process manufacturing inventory items by using aquisition cost window. But, how could it be ap