JTree sizing question...

Hello:
I have a JTree for which each cell contains a button. I have written a renderer that renders the button, and I realize that I have to do some special stuff to capture a click on the button. My question is unrelated to all of that.
The problem is that over time, the labels on my buttons change (and may become longer (wider)), but the tree size does not change. In fact, when I update the button label and the tree is re-rendered the rendering of the button gets "chopped off". I've put the tree in a scroll pane, but this doesn't help - the right side of some of the buttons get cut off to the original tree size. I've tried lots of different variations on setPreferredSize, calling repaint, etc, and am not having any luck. I've put together a demonstration of this behavior in a smallish application that I'm posting here, where I create a 2 node tree with buttons that read "Hi", then I change the button labels to "Goodbye" and re-render. You'll see that the button's are cut off about halfway through the button.
In case its important - I'm running java version 1.5.0_07 on a 32-bit Linux box.
Any help would be greatly appreciated. Thanks in advance!
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
public class JTreeQuestion
  public static void main(String [] args)
    JTreeFrame f = new JTreeFrame();
    f.pack();
    f.setLocation(30, 30);
    //Draws buttons with "Hi" (short string)
    f.setVisible(true);
    ButtonNode.updateString("Goodbye");
    //Draws buttons with longer string, buttons get "cut off"
    f.repaint();
class JTreeFrame extends JFrame
  JTree tree;
  JScrollPane treeView;
  public JTreeFrame()
    super("My Tree");
    DefaultMutableTreeNode root;
    root = new DefaultMutableTreeNode(new ButtonNode());
    root.add(new DefaultMutableTreeNode(new ButtonNode()));
    tree = new JTree(root);
    tree.setCellRenderer(new ButtonNodeRenderer());
    treeView = new JScrollPane(tree);
    add(treeView);
class ButtonNode
  public static String str = "Hi";
  public static void updateString(String inStr)
  { str = inStr; }
  String getStr()
  { return str; }
class ButtonNodeRenderer extends DefaultTreeCellRenderer
  public Component getTreeCellRendererComponent(JTree tree,
                          Object value, boolean sel, boolean expanded,
                          boolean leaf, int row, boolean hasFocus)
    Box theBox = new Box(BoxLayout.X_AXIS);
    super.getTreeCellRendererComponent(tree, value, sel, expanded,
                                       leaf, row, hasFocus);
    DefaultMutableTreeNode jtreeNode = (DefaultMutableTreeNode)value;
    theBox.add(new JButton(((ButtonNode)jtreeNode.getUserObject()).getStr()));
    return (theBox);
}

For those who are interested. The DefaultTreeModel has a method named nodeChanged() that tells the tree model that a specific node has changed, and the model re-interprets the cell causing its sizse to change as necessary, so that the full button is rendered now.
Basically what I did was instead of calling repain, I call a method that I wrote that loops through all the tree nodes, indicates they have changed, then repaint's, and it all works out. My trees are relatively small, so this is fine, but if others face the same problem, you'll probably want to selectively indicate which nodes have changed so the tree model doesn't have to do more work than necessary.

Similar Messages

  • JTree image question

    I have a question about using images in a JTree.
    I have like 2 parent nodes who both have a lot of child nodes now i know how to get an image for every node but how do i get 1 image for 1 parent with all his children and another image for the other parent with his children.

    It is a programming problem because i dont know how to give echt DefaultMutableTreeNode his own picture. You should think of it like msn when you log in your contacts are in a Tree and your offline contacts have a red icon and online contacts have green one. I need to to the same for my program(chat program). But i can't figure out how but i know how to give alle the DefaultMutableTreeNode's a picture but i cant give individual one's a picture.
    I hope i cleared things up :)

  • JTree#expandRow() Question

    JTree tree;
    //etc...
    1) /** Expand the tree */
    for (int i=0; i<tree.getRowCount(); i++)
         tree.expandRow(i);
    and tree.getRowCount() = 6
    2) /** Expand the tree */
    for (int i=0; i<6; i++)
         tree.expandRow(i);
    My tree has 6 rows, and each row has its own sub-tree hierarchy.
    I wonder why the first case will expand the whole tree, which includes
    the subtrees of each row.
    But in second case, it only expands the first 6 rows in the tree.
    So basically the question is why (1) and (2) have different tree view outputs??

    Well, after you expand row 1, the row count isn't 6 anymore, is it? It's something larger than that, depending on how many children the first node has.

  • JTree Updating question

    Hi there. I have two questions.
    I have a data structure that is being displayed in a JTree, so I made a Model and it works great. The data structure can be updated from non-gui interaction. The nodes don't change position or anything, its just the data that is displayed is changed. I handle it currently by calling a function in the model I made called nodesChanged(), which basically does the following:
    public void nodesChanged()
        int len = treeModelListeners.size();
        TreeModelEvent e = new TreeModelEvent(this, new Object[] {rootItem});
        for (int i = 0; i < len; i++) {
          ( (TreeModelListener) treeModelListeners.elementAt(i)).treeNodesChanged(e);
      }It does actually work, the changes are reflected in the JTree, but it seems a little expensive, and the updates to the actual data model could come at about 150 per second. To deal with that now, I just use a timer class that updates it about every 3/10's of a second, which does a pretty good job, but is there a more elegant way to do this? Something where the node is an observer of the data in the data structure (which are Observable objects)?
    The second question I have is when I do the above, sometimes the display name of the node will be larger than the value it had previously, but the Textbox (if that's what it is) doesn't grow, so I get a ... at the end.
    For example, if I have "Run" and it changes to "Stopped", it will show up as "Sto...".
    Any help would be great. TIA.

    well, you can start by making the node you put in the tree model event the lowest node in the tree that needs updating, instead of root.
    I don't know about the timer thing, cuz as far as I know, the listener will invoke code that will refresh the renderers, as opposed to painting where repaint calls can be merged into one. If you aren't getting that many updates all the time, you could implement something where the listener fires to an intermediate listener which will fire the info to the tree after a slight delay. That way if you get multiple updates, you can effectively ignore lots of them.
    The ... thing, I thought that treeNodesChanged was the appropriate method, although maybe it has to be for the specific node, not root.

  • BW-SEM hardware sizing question

    Hi all, please help me with sizing process
    Now I'm doing sizing of the big BW-SEM system.
    I'm using quicksizer and document "Sizing ASAP FOR BW ACCELERATOR" (https://websmp102.sap-ag.de/~sapidb/011000358700001951182003)
    There is such phrase: "In a comparison of SAP BW benchmark results with SD benchmark results we have obtained a factor of 2.28" (page 11)
    what type of SAPS I obtain from quicksizer - SD or BW?
    So,  should I result from quicksizer tool multiple by 2,28?
    Are there any official documents for this question?
    Thanks in advance,
    Best regards, Elena

    Hi;
    Currently our current 11.5.10 Production is running on a Two node architecture on HP-Unix PA-RISC with the 128 GB of RAM on the Application Server and 256 GB RAM on the DB Node.
    For R12 the servers will be on HP-Unix Itanium and the sizing has been factored as 128 GB for the Application server and the DB will be on RAC with 128 GB of RAM each on the DB Nodes.
    I want to know is the sizing correct?
    When sizing a RAC Env is it ok to just split the current configuration into two and size the same on two nodes?
    Please share your experiences.We do not know how your machine has process which mean we do not know your activiy on your system. You can check some benchmark
    http://www.oracle.com/us/solutions/benchmark/apps-benchmark/ebs-standard-benchmark-overview-192676.html
    Its also important how mch cpu you have.
    Let me give you example from our system. We have 2 node apps server, 2 node rac and db size is almost 18T and our system is working nonstop. Our db has 30CPU and 120g RAm for each node. For apps cpu count and ram count are not like that.10 CPU and 20G ram.
    We are happy wiht apps side, but we still working on better performance issue for our db side
    Regard
    Helios

  • SD - situation/effort analysis, sizing questions.

    Hi,
    do not you know if there is some SAP methodology or template which will enable me to get an overview about size of the AS IS situation from sales and distribution point of view in an company?
    I am looking for ideally list of questions which will allow me to estimate effort that will be needed for sucesfull rollout.
    Example of questions coming to my mind....will existing business processes be only used or new have to deployed? How many sales areas (or e.g. shipping points) needs to be created? Etc.
    Please consider this should be an SAP rollout for more distribution center(s).
    Thank you!

    Get a copy of the SAP ASAP methodolgy and use that  or see if you can get a copy of a blue print that has the questions already included and work your way through it.

  • JTree event question

    Hi,
    I am facing a problem and hoping somebody here can give me a clue.
    I have a JTree in my application, which has different types of nodes (all implement TreeNode ). One node there needs lazy-loading, what I want is when user clicks either '+' or folder icon/label then this node gets updated. I have added MouseListener to the tree, it works fine with clicking folder icon or label but not for clicking '+'. I also tried adding other listeners like TreeWillExpand etc. but it not seems a good solution to me since I just need to treat one node defferently.
    There are a couple of options I think can help:
    - catch clicking '+' event for specific node
    - display '+' even folder has no child (just for one node)
    - or disable '+' for this node
    Thank you in advance

    Well, after you expand row 1, the row count isn't 6 anymore, is it? It's something larger than that, depending on how many children the first node has.

  • Catalog database sizing questions

    Hi There,
    We need to create an RMAN catalog that would be able to support 8 databases 5 of which are around 50gb(40GB db files+10gb arcglogs) and the remaing 3 are about 120gb (100 db files and 20 archlogs).
    Does anyone have any sizing recommendations regarding memory structures (sga, pga, large pool)? disk space? We are using Oracle 11.1.0.7 on windows 2008 server. The server itself is an intel box, dual core E5440 - with 16gb RAM.
    Thanks

    Hi rsar001,
    The size of the catalog schema and database in your setup will not grow to more than 1GB (as long as you maintain a retention policy).
    Just set sga_target to 1G.
    As an example I have around 100 databases with sizes bewteen 10 GB and 2T and run a daily backup on all of them retention policy 1 month.
    The catalog is and stays around 700M for more than 2 years.
    Rgds,
    Tycho

  • Sizing Question

    I am using the quicksizer tool and had a question that I could not find the answer to in any quicksizer documentation.
    When you fill out the EP quicksizer active users table there are 4 scenario categories:
         NW-EP-ESS (Employee Self Service)
         NW-EP-INT (EP Intranet scenario)
         NW-EP-PCC (EP People Centric Scenario)
         NW-EP-PRT (EP Custom developement scenario)
    Do I fill out all 4 scenarios or just one. And if a user exists in both do I add them to both?
    Appreciate your assistance,
    Tom

    With the help of a collegue I was able to figure it out. These 4 categroies in the quicksizer are just for notation. It really doesn't matter where you put the data. The only thing you need to fill out is concurrent users, think time, java iviews per page, url iviews per page, % KMC and total users logins within an hour.
    Regards,
    Tom

  • Sizing question (beware newbie)

    Hi all,
    Here’s a question from a true newbie, I hope it is not
    to ignorant to answer though.
    It might be the case that this question has been addressed
    somewhere in this forum already but that I don’t recognize
    the problem due to terminology, to which I’m still to new.
    The other problem is that don’t have the site online so
    it’s not possible to show it live.
    I’ve tried to make an index page (html) with an image
    in the middle like a bar. On this bar a few buttons are placed.
    When I preview this page in a browser it looks right at first but
    when I use the ctrl button and scroll-wheel, (normally altering the
    text size) it completely changes the size of the size except for
    that bar image. The buttons appear somewhere else on the page. (not
    a pretty picture)
    Is there a way to prevent the use of ctrl combined with the
    mouse scroll-wheel?
    It was told me that using fonts measured as pixels this
    wouldn’t be possible but that didn’t prevent this to
    occur.
    Thanks for any help.
    Kind regards,
    Lexz.

    http://apptools.com/examples/pagelayout101.php
    Then move on to these -
    http://www.projectseven.com/tutorials/css/qdmacfly/index.htm
    http://www.macromedia.com/devnet/mx/dreamweaver/css.html
    http://www.macromedia.com/devnet/dreamweaver/articles/tableless_layout_dw8.html
    http://www.macromedia.com/devnet/dreamweaver/articles/css_concepts.html
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "lexdepax" <[email protected]> wrote in
    message
    news:fn53i6$fet$[email protected]..
    > Ok, that's a clear answer Bregent. Thanks for that.
    > Now as a complete newbie the queston that comes to mind
    is:
    >
    > Is that something one can do visually ( I mean in Dream
    Weaver) or is that
    > always managed from the code itself, which seems to me a
    difficult job.
    > It was so temting to be able to visally place my stuf
    anywhere I wanted
    > it.
    >
    > What would you suggest as the right approach for a
    starter?
    >
    > Thanks again.
    >
    > Regards,
    >
    > Lexz
    >

  • JTree path question

    I have created a program that basically simulates single celled organisms in a random (non graphical) world, and I want to use a JTree to show the family history and allow the user to bring up an organism's stats by clicking on in the the Jtree, but I have a problem. Each organism has a unique ID number (starting at 0) and that's what I want to display on the tree. I have the code working to add the new organisms to the root, but I want them added as a child to the parent (each child has only one parent for these organisms), but I don't know how to do it. I tried using insertNodeInto but since everything after the root is dynamically generated I don't know how to identify the parent correctly (just using the ID doesn't seem to do anything). Do I need to create a method that somehow copies the entire treemodel into a collection and steps through it? I have the organisms in a collection already (an arraylist to be exact), so I could figure out the lineage by stepping through that, but then how do I build a 'selection path' object that will work to tell Java exactly where I want the child to go? Is the selection path just some kind of array, or is it even possible to build a selection path without a user clicking on a tree node? I hope you can figure out what I'm trying to say here and I appreciate any help you can give.

    Start by creating a Map that has your organisms as the key and the nodes they are in as the value. Or just let the organism include a reference to the node that contains it. Either of those would allow you to identify the TreeNode that contains a particular organism.

  • Jtree - beginner question

    hi,
    i wanted to build a jtree and have started the swing tutorial on it, seems small, but i wanted to know is it easy to build a jtree to map the file system? something like windows explorer? i wanted to build a ftp utility and wanted to show the local and remote drives and file systems in a scroll pane, so i was thinking about using a jtree, first time i've had to use it, so i'm a little new to it.
    Thank you.

    Search Google for "java file explorer"
    --A                                                                                                                                                                                                                       

  • JTree Icon question

    Currently, ALL leaves in the JTree are displayed with a certain icon that looks like a piece of paper. What should I do if I want only leaves at depth 4 to have the piece of paper icon and all the rest to have folder icons even if they are leaves?
    Thanks

    I guess a custom renderer is in order.
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display

  • JTree Important Question

    Hi All,
    in the JTree, is there a way to change the root handles
    icons, not through the UIManager?
    I need the Changes to apply only for the one instance.
    is there a key for the putClientProperty method?
    a work around through the TreeCellRenderer is possible to
    write, but seems as a bit of a waste.
    10x in advance

    OK. If "handle" means the leftmost icons, that is the little circle with a dash pointing right or down under Java L&F, or either a + or a - in a square under Windows & Motif L&F, they are NOT part of the node display, and so they are not dealt with by a renderer. They are completely L&F dependant (while the leaf, open, closed are renderer dependant, and the L&F just provides some "hint" to the default renderer). It is possible that some L&F would display trees in a completely different way, without handles. So this is the tree UI delegate business, not the renderer's.
    You can set the icons for the application globally by setting UIManager properties Tree.expandedIcon and tree.collapsedIcon. (you knew that already). The good news is that the UI delegate seems to get these icons once sometime when it is created, rather than asking the UIManager each time it needs them.
    I tried
        Object previousExpanded = UIManager.put("Tree.expandedIcon", myExpandedIcon);
        Object previousCollapsed = UIManager.put("Tree.collapsedIcon", myCollapsedIcon);
        tree2 =  new JTree(data);
        UIManager.put("Tree.expandedIcon", previousExpanded);
        UIManager.put("Tree.collapsedIcon", previousCollapsed);.
    There is a tree1 created before and a tree3 afterwards, and it works fine, that is only tree2 get my icons.
    I tried to go a little farther, as I am not sure when the ui delegate might get reset. So I wrote a descendant of JTree to do the job in updateUI.
    public class CustomHandleTree extends JTree {
      // republish ancestor non-default constructors
      Icon expanded = null;
      public void setExpandedIcon(Icon anIcon) {
        expanded = anIcon;
        updateUI();
      // do the same for collapsed
      public void updateUI(){
        Object defaultExpanded = null;
        if (expanded != null)
          defaultExpanded = UIManager.put("Tree.expandedIcon", expanded);
         // collapsed stuff too
         super.updateUI();
        if(expanded != null)
          UIManager.put("Tree.expandedIcon", defaultExpanded);
         // collapsed stuff too
    }It works too, and I can even set the handles dynamically, when clicking on some button. It refreshes properly.
    The bad news is that I found that by trial and error, and have no single line of documentation to explain why it should work.
    Hope it helps nevertheless.
    Regards.

  • Enterprise DQ - hardware and sizing question

    Hi, we are considering implementing Oracle Enterprise Data Quality (all components) and would like to know the hardware (memory, number of CPU's, etc.) sizing parameters/requirements for this software.  Obviously, data volumes are a key factor.  I'm hoping someone in this community can indicate the "hardware" size they have implemented DQ on and if there are any concerns/issues that, if not considered, can have an adverse impact on the performance and operation of this software stack.
    Thank you.
    Brian.

    Hi Brian,
    See my response to your separate mail.
    Regards,
    Mike

Maybe you are looking for

  • Problems with HDMI signal

    I used to connect my macbook pro 13" 10.7.3 to my LCD TV by minidisplay port to HDMI, it worked since december 2011 until yesterday. Now it does not work, my TV does not recognize the signal. How can I solve it?

  • Safari 1.3.2 and Yahoo! "Search" functions

    I am running Mac OS X 10.3.9 with Safari 1.3.2. Insatlled Safari "add-ons are Acid Search, PithHelmet and Safari NoTimeout. When I go to the Yahoo! home page, in the upper right of the page are the Yahoo! Search options (Web, Images, Video, etc.). In

  • GRANT IMAGES DISPLAY

    Hello everybody. Im working with Centos 5, Oracle Databse 10 GR2 and Apex 3.0.1 I have a problem of grants I think, maybe Im in mistake. Im using this code to display images in Apex applications pages. select mime_type, imagen, referencia, dbms_lob.g

  • Business Connectors

    Can someone tell me how to detect the requirement of BPM on the Business Connector developer side among the flow services. How to detect if there exists BPM in the package at BC developer or not? thanx

  • How do we link multiple stop buttons to make one master stop button?

    I am building a program that has multiple loops running simultaneously. How do I create a master stop button/link the multiple stop buttons to one? Right now I have 14 different stop buttons and would like to control them all with one main stop butto