A bug in the JTree(Missing some nodes)

I have an application which implement a JTree & DnDTree. The left hand side is the original JTee, the right hand size is DnDTree which allows user to Drag and Drop some node from left JTree. The bug is: when I grag some node to right DnDTree, once I then click the left JTree, some nodes will be missing. I try my best for more than one week, but still couldn't fix it, could anybody take time to fina a way to fix it? The piece of code of creating JTree is as follow:
/*public void createTestTree()
DefaultMutableTreeNode rootRight = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode root = createTreeModel();
treeLeft = new DnDTree(root, true); //JTree(root, true);
treeLeft.putClientProperty("JTree.lineStyle", "Angled");
treeLeft.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
treeLeft.addTreeExpansionListener(new TreeExpansionListener(){
public void treeCollapsed(TreeExpansionEvent e) {
public void treeExpanded(TreeExpansionEvent e) {
UpdateStatus updateThread;
TreePath path = e.getPath();
FileNode node = (FileNode)
path.getLastPathComponent();
if( ! node.isExplored()) {
DefaultTreeModel model = (DefaultTreeModel)treeLeft.getModel();
UpdateStatus us = new UpdateStatus();
us.start();
node.explore();
model.nodeStructureChanged(node);
class UpdateStatus extends Thread {
public void run() {
try { Thread.currentThread().sleep(450); }
catch(InterruptedException e) { }
SwingUtilities.invokeLater(new Runnable() {
public void run() {
treeRight = new DnDTree(rootRight, true); treeRight.putClientProperty("JTree.lineStyle", "Angled");
treeRight.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
treeRight.addTreeExpansionListener(new TreeExpansionListener(){
public void treeCollapsed(TreeExpansionEvent e) {
public void treeExpanded(TreeExpansionEvent e) {
UpdateStatus updateThread;
TreePath path = e.getPath();
FileNode node = (FileNode)
                         path.getLastPathComponent();               
if( ! node.isExplored()) {
DefaultTreeModel model = (DefaultTreeModel)treeRight.getModel();
UpdateStatus us = new UpdateStatus();
us.start();
node.explore();
model.nodeStructureChanged(node);
class UpdateStatus extends Thread {
public void run() {
try { Thread.currentThread().sleep(450); }
catch(InterruptedException e) { }
SwingUtilities.invokeLater(new Runnable() {
public void run() {
My FileNode class is:
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.EventObject;
public class GoodFileTree extends JPanel {
     public GoodFileTree() {
          final JTree tree = new JTree(createTreeModel());
          JScrollPane scrollPane = new JScrollPane(tree);
          this.add(scrollPane, BorderLayout.WEST);
          //getContentPane().add(scrollPane, BorderLayout.CENTER);
          this.add(GJApp.getStatusArea(),BorderLayout.SOUTH);
          //getContentPane().add(GJApp.getStatusArea(),BorderLayout.SOUTH);
          tree.addTreeExpansionListener(new TreeExpansionListener(){
               public void treeCollapsed(TreeExpansionEvent e) {
               public void treeExpanded(TreeExpansionEvent e) {
                    UpdateStatus updateThread;
                    TreePath path = e.getPath();
                    FileNode node = (FileNode)
                                        path.getLastPathComponent();
                    if( ! node.isExplored()) {
                         DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
                         GJApp.updateStatus("exploring ...");
                         UpdateStatus us = new UpdateStatus();
                         us.start();
                         node.explore();
                         model.nodeStructureChanged(node);
               class UpdateStatus extends Thread {
                    public void run() {
                         try { Thread.currentThread().sleep(450); }
                         catch(InterruptedException e) { }
                         SwingUtilities.invokeLater(new Runnable() {
                              public void run() {
                                   GJApp.updateStatus(" ");
     private DefaultMutableTreeNode createTreeModel() {
          /*File root = new File("E:/");
          FileNode rootNode = new FileNode(root);
          rootNode.explore();
          return new DefaultTreeModel(rootNode);*/
          DefaultMutableTreeNode top = new DefaultMutableTreeNode("Root");
          File[] fArr = File.listRoots();
          File fDrive;
          FileNode driveNode;
          for(int i=0; i<fArr.length; ++i)
               fDrive = fArr;
               driveNode = new FileNode(fDrive);
               top.add(driveNode);
          return top;
     /*public static void main(String args[])
          try
               UIManager.setLookAndFeel(
               UIManager.getSystemLookAndFeelClassName()
               //UIManager.getCrossPlatformLookAndFeelClassName()
          catch (Exception e)
          GJApp.launch(new GoodFileTree(),"JTree File Explorer",
                                        300,300,450,400);
class FileNode extends DefaultMutableTreeNode {
     private boolean explored = false;
     public FileNode(File file)      {
          setUserObject(file);
     public boolean getAllowsChildren() { return isDirectory(); }
     public boolean isLeaf()      { return !isDirectory(); }
     public File getFile()          { return (File)getUserObject(); }
     public boolean isExplored() { return explored; }
     public boolean isDirectory() {
          File file = getFile();
          return file.isDirectory();
     public String toString() {
          File file = (File)getUserObject();
          String filename = file.toString();
          int index = filename.lastIndexOf(File.separator);
          return (index != -1 && index != filename.length()-1) ?
                                             filename.substring(index+1) :
                                             filename;
     public void explore() {
          if(!isDirectory())
               return;
          if(!isExplored()) {
               File file = getFile();
               File[] children = file.listFiles();
               for(int i=0; i < children.length; ++i)
                    add(new FileNode(children[i]));
               explored = true;
class GJApp extends WindowAdapter {
     static private JPanel statusArea = new JPanel();
     static private JLabel status = new JLabel(" ");
     public static void launch(final JFrame f, String title,
                                   final int x, final int y,
                                   final int w, int h) {
          f.setTitle(title);
          f.setBounds(x,y,w,h);
          f.setVisible(true);
          statusArea.setBorder(BorderFactory.createEtchedBorder());
          statusArea.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
          statusArea.add(status);
          status.setHorizontalAlignment(JLabel.LEFT);
          f.setDefaultCloseOperation(
                                   WindowConstants.DISPOSE_ON_CLOSE);
          f.addWindowListener(new WindowAdapter() {
               public void windowClosed(WindowEvent e) {
                    System.exit(0);
     static public JPanel getStatusArea() {
          return statusArea;
     static public void updateStatus(String s) {
          status.setText(s);
Thanks in advance.

Hi Paul,
sorry for my late reply, but I usually don't work on weekends (this time it was an exception).
OK, then, to your problem:
- at the first look I thought you did NOT follow all the instruction (namely, the constructor of your trees has no info that you want to use model, or whatsoever), but later I realized that your approach: create the tree first and then assign a model to it (or in fact, get the model from the tree via: tree.getModel()) might work as well
- having no debugger I am not able to have much clue about your program / and it seems that you coding suffers from your being in a hurry:
- no comments - don't know which method is expected to do what
- misleading names (createTreeModel does nothing with the model, but creates some new nodes??)
therefore, I'm sorry, but I'm not able to detect exactly where the error is.
- anyway, having a quick glance on your code I have some suspections:
- you have 2 trees (treeLeft, treeRight), but just one model (model)
( it seems that you assign it dynamically when needed - either you take the model of the left or of the right tree)
- however, when this assignment takes place (in createTestTree()), you DO NOT ASSIGN IT to the class' protected attribute model, but to a local variable model (of the same type, however - since you introduce it as:
DefaultTreeModel model you override the model from class' attributes) - therefore, your assignment is no valid when the block in which ot is located is finished
- note, that you NEED the model when you add/delete nodes of the tree (somewhere in DnDTree? - then quite probably your local assignment of model is not valid any longer)
My suggestion, therefore, is:
somehow try to encapsulate the model to your tree (note that I only created the model outside the tree, because I needed it for running the constructor, but all other usages of the model are made WITHIN the class of the tree) - the best, do it the same way - through the constructor
then, in the place when you insert/remove nodes you will have no problem at all
I will e-mail you my whole "project" so that you may observe all parts - how it's written. I trust if you can't figure it out from my writings here (maybe I missed the point) you may get it from that example.
Hope it helps - GOOD LUCK

Similar Messages

  • Mac with Lion OX, in print preview with PDF, only page 1 comes correctly, the rest misses some portion rest not

    I have iMac desktop with Lion OS. I am using Firefox 6 web browser. Previously with Snowleopard OS I did not have any problems with printing, With Lion OS print commands have changed and when I click preview in PDF format for printing a web page, only page 1 of the document shows correctly. In second page, the text does not show all of the document and few lines at the boundary is missing and the font is different from page 1. I tried using Google Chrome browser and this does not have this problem. If I do not find a solution I may be forced to move to Google Chrome. I will really appreciate a response. Thanks.

    Why not reconstruct the pages in InDesign they way you want the double pages to appear. There may even be an imposition script available that will do the trick. You could then output to pdf all the pages you want the full spread on. Leave the original to create the pages you wanted left as is.
    You can ask in the ID forum about an imposition script. I know there was one with CS4, there may have been one with CS3.

  • Bug in the installation - Missing option to install Eclipse

    Hi there. I've got a weird issue installing build 569 where it is expecting that I already have Eclipse 3.2 pre-installed and it doesn't give me the option to select the bundled Eclipse. The file is downloaded is named FullWorkshopStudioTrialInstall-569.zip.
    Thanks
    --Vinny
    vcarpent at wellsfargo.com

    Please provide the following information:
    What OS are you working on?
    Re-launch installer and hold Cntrl key until a console pops-up in the background, continue with the installation - Do you see the "Choose Eclipse" screen similar to the one at http://edocs.bea.com/workshop/docs92/studio32/Installation/InstallationInstructions.html#Plugin
    If not, describe the exact steps and also send the debug statements to [email protected]
    FYI: Indeed it is a weird scenario which I am not able to reproduce. As a workaround you can download WTP1.5      (wtp-all-in-one-sdk..) and install Workshop as a plug-in.

  • After iOS 5 update i only have music and apps the same. missing some iOS 5 features

    i lost contacts, photos, favorites, messages, notes -- everything except my apps and music. i synced before many times. how do i retrieve this????

    Update: I managed to restore everything back to the sync I did right before I updated to iOS. We're going on 5 hours now of f***ing with this phone but hopefully now all I have to do is rearrange all my apps again...
    I CTRL clicked on my phone in iTunes and thankfully the backup I did last night showed up in the pop up menu. It gave me the option to "restore from backup" and I chose that one. When it finished the restore everything looked like it did yesterday except I had the new features of iOS. Hooray! Hope this works for you, too.

  • Download Presenter trial in your website but when I published object scorm in zip file miss some important file such as ismmanifest.xml. In fact Moodle upload is wrong! Is it a bug or what? Thank you.

    Download Presenter trial in your website but when I published object scorm in zip file miss some important file such as ismmanifest.xml. In fact Moodle upload is wrong! Is it a bug or what? Thank you.

    You can publish Adobe Presenter Projects to your Moodle LMS (this will work for many other LMS’ too.)Please follow the steps as mentioned in the blog linked below.
    https://blogs.adobe.com/presenter/2013/08/step-by-step-how-do-i-publish-my-presenter-cours e-to-my-learning-management-system.html#more-6260
    Regards,
    Rajeev.

  • JTree scrollbar problem - can't scroll back to top when some nodes hidden

    I have a problem which I cannot resolve: I have a JTree which has had 88 rows added to it, and which then has 15 or so rows set to be not visible; when I then scroll to the bottom of the pane I am unable to scroll all the way back to the top using either the scroll button at the top of the bar or the mouse scroll wheel although I can drag the knob to get to the top; using the button or wheel, the scrolling stops somewhat short of the top; via testing I've found that the AdjustmentEvent is not fired when it reaches that point. Anyone seen this before and/or know a way around it?
    Thanks in advance,
    Mike

    MikeAuerbach267 wrote:
    It turns out that my problem was due to the fact that I am using my own TreeCellRenderer which makes invisible some nodes via user option but doesn't reload the tree; hence the confusion as to the scrollbar size. I now correctly reload after user option has changed rather than render nodes invisible and all is fine. Which reinforces Andrew's view in reply #1 that a 'vague waving about of hands' does not allow the forum members to help.

  • Some Nodes missing in CCMS Exchange Infrastructure "System Errors"

    Hi All,
    I have configured the ccms for XI System PI 7.0.But there are some nodes that are missing under system errors in XI node of CCMS
    Nodes present under system errors in XI:
    outbinding
    mapping
    Nodes that are missing under system errors in XI:
    XIcache
    Rcvr_determination
    if_determination
    internal
    message.
    Any help greatly appreciated
    Aravind

    pls check the following URL:
    - /people/dirk.jenrich/blog/2007/01/21/how-to-use-the-monitor-set-sap-ccms-technical-operation-templates
    - /people/sap.india5/blog/2005/12/06/xi-ccms-alert-monitoring-overview-and-features
    A+

  • PDF file is missing some text while displaying on the iPad

    I have sent a PDF Invoice to my customer, he called me back and said that I must be joking because half the important text is missing.
    I have opened up the PDF on my computer and everything was there, so I was scratching my head... Than he called me back and said that
    he also opened up the file on his computer and the missing text was there. That way we have discovered that the PDF file is for some strange
    reason not displaying some parts of the text. I have checked on my own iPad trying to display it in iBooks, Adobe Reader, directly in a mail app,
    everywhere I could only see a part of the text.
    Can someone please explain to me how to fix this on the iPad or within the PDF itself?
    Thank you.

    Have you tried viewing the page at any different (even just slightly different) magnifications?
    I have what may be a related problem.  I created a PDF file from InDesign's "Export" to PDF feature. (See it at http://www.mydfz.com/pot20/2046today.pdf). When I went to that web page and opened it, I noticed a problem on page 2 as follows:
    The ad for "Duds-N-Suds Laundromat" should say "20, 30, & 40lb Dexter machines" between the company name and their hours. If I click on the icon to show the whole page, that space is blank. If I increase or decrease magnification the text appears. The whole page setting is shown as 86.5%. If I type that specific percentage in the box, the text appears. It is only when I use the whole page icon that the text vanishes.  If I try to access the original file on my own machine, the text in question is visible under all the conditions I tested. I couldn't get it to vanish.
    I just tried to access the web version again and this time the text is missing no matter what I do!  I uploaded a fresh copy of the file but it still won't show the text. Very strange!
    Evidently there is some bug in the rasterization routines but it only manifests under certain non-obvious circumstances. I grabbed screen images of the two states (visible and vanished) and will be happy to email them to anyone interested in pursueing this further.

  • How to get the JTree path including the rest of its node

    I want to listen for expansion and collapse events in a JTree including the rest of all its children and nodes. Because if the tree have some similar or same nodes at the upper level, it is hard to know which node has been selected. That is why I want to know all its children.
    I think the traditional way can not be implemented.
    JTree tree = (JTree)evt.getSource();
    TreePath path = evt.getPath();
    Does someone has any idea?
    Thank you.

    My code below turns the selected node in a tree into a Complete Window's Style Path:
        //Get the Path
        TreePath path = tree.getSelectionPath();
        String address;
        if (path == null) return;
        address = new String();
        //Convert Path to String: format is [ root , subtree1, node2, child 3] etc
        address = path.toString();
        //Lop first bit off leaving root, subtree1, node2, child 3]
        address = address.substring(1);
        //Convert ", " into "\" character to make root\subtree1\node2\child 3]
        //replaceAll method uses regular expressions - hense \\\\ only equals one
        ///after being processed..
        address = address.replaceAll(", ","\\\\");
        //remove trailing ]
        address = address.replace(']','\\');This may be what your looking for, or alternatively, it may not.
    Hope it helps set you in the right direction.
    Phillip Taylor
    www.geocities.com/PhillipRossTaylor/

  • TS1702 My iPhone 4s didn't do it until the latest update so imnpretty sure it's on the apple server some sort of bug maybe? Not sure. But whatever it is I really would like to download apps. It won't let me download any apps and my phone is brand new

    My iPhone 4s didn't do it until the latest update so imnpretty sure it's on the apple server some sort of bug maybe? Not sure. But whatever it is I really would like to download apps. It won't let me download any apps and my phone is brand new.

    Sorry guysy iPhone says unable to download application at this time and I try all day and it still won't let me download no matter how hard I try.

  • Apple recently replaced my broken iPhone 5 with a new one. I backed up all my stuff in iCloud. When I set up the new phone I apparently used a back up from an earlier date. Now I am missing some of my stuff. How do I go back and use the most current I cln

    Apple recently replaced my broken iPhone 5 with a new one. I backed up the contents of my phone with iCloud.
    When setting up my new phone I used an iCloud back up from an earlier date. Now I am missing some of my most recent stuff. How
    Do I go back to use the proper iCloud back up to set up my new phone?

    Tap settings> general> reset> erase all content and settings...then you'll have a chance to setuo your phone again

  • Hello there! i am using Adobe acrobat pro DC and using windows 8.1. Recently I was trying to convert a web page (includes greek letters) into pdf. I noticed that the conversion is not accurate, some words are missing, some are misplaced. Especially greek

    hello there! i am using Adobe acrobat pro DC and using windows 8.1. Recently I was trying to convert a web page (includes Greek letters) into PDF. I noticed that the conversion is not accurate, some words are missing, some are misplaced. Especially Greek words are not accurately converted or even not converted. Please give me some suggestions to improve this issue. Regards

    Hey quantum info,
    Thank you for posting at Adobe forums. We would love to help you out.
    Could you please let me know if you have tried converting other web pages to PDF and checked if the same issue persists.
    How have you been trying to convert the web page to PDF?
    Are you trying to convert to PDF directly via browsers or using "File > Create > PDF from Web Page"  option in Acrobat.
    Let me know more so that I can analyze where actually the issue persists.
    Hope to hear from you.
    Regards,
    Anubha

  • HP Stream 7 The boot configuration data file is missing some required information

    I have an HP Stream 7 tablet.  When I open it up it shows a blue screen with the error "The boot configuration data file is missing some required information."  Can anyone help as I can't get into the tablet to solve the error!

    Hey @PaD2 ,
    Welcome to the HP forums.
    I understand you're unable to boot up your Stream 7 tablet.
    Try accessing the recovery partition by holding the volume down button and power button at the same time. Please excuse my ignorance, as exact information on accessing the recovery manager appears to be unavailable for this exact model. If the down button doesn't work, up should get you in.
    Once in the recovery manager you should be able to select Troubleshoot > Startup repair. 
    If the startup repair does not fix the issue I would suggest trying the full system recovery option, which you should find under Troubleshoot > Advanced.
    Thanks.
    Please click the "Kudos, Thumbs Up" at the bottom of this post if you want to say "Thanks" for helping!
    Please click "Accept as Solution" if you feel my post solved your issue, it will help others find the solution.
    The Great Deku Tree
    I work on behalf of HP.

  • How could i get the selected node in the JTree

    getLastSelectedPathComponent() �returns the parent node of currenr selected, so how could I get the selected node itself in the JTree
    I will appretiate for any help!

    i think you can get by....
    TreePath treePath = tree.getSelectionPath();
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();

  • JTree rendering extra node and leaf icons at the end of the label

    Hi,
    Does anyone know how to add an icon to a JTree node or leaf in such a way that it will be displayed behind the text label?
    In an example:
    - rootnode
    - childnode [icon]
    |- leaf
    + childnode [icon]
    Where -/+ are the default (un)collapse icons
    I'd like to apply this to show additional information by using icons with respect to a node.
    I couldn't find anything on the net besides changing the default open/close node icons, yet that's not what I'm aiming for here.

    use this one.I think it will help u.Gd lk
    tree =new JTree(root);
    DefaultTreeCellRenderer renderer =(DefaultTreeCellRenderer)tree.getCellRenderer();
    renderer.setLeafIcon(new ImageIcon(getClass().getResource("leafimages/3.gif")));
    renderer.setClosedIcon(new ImageIcon(getClass().getResource("leafimages/1.gif")));
    renderer.setOpenIcon(new ImageIcon(getClass().getResource("leafimages/2.gif")));
    renderer.setBackgroundNonSelectionColor(new Color(15,85,134));
    renderer.setBackgroundSelectionColor(Color.YELLOW);
    renderer.setTextNonSelectionColor(new Color(217,227,227));
    renderer.setTextSelectionColor(Color.RED);
    renderer.setHorizontalTextPosition(SwingConstants.LEADING);
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
    tree.setFont(new Font("Tahoma",1,12));
    tree.setBackground(new Color(15,85,134));

Maybe you are looking for

  • Index Error While creating a new reporting type application.

    Hi, I'm trying to create a new application of reporting type with finance as the selection.After I make the selection and go the the next steps for completion, there is this error message coming up. " Index  was out of range. Must be non negative and

  • Mass creation of Material Master Records

    Hi all, I have to create 50.000 materials the first time and then, once a month, I have to manage the update of 50/100 materials. What do you suggest ? Direct input the first time and Idoc (Matmas) to manage the updating? Thanks in advance Bye

  • Login page error in the ISA b2b 5.0 application.

    Hi all i deployed the CRM ISA b2b 5.0 application successfully in the j2ee engine and after that i have done the XCM configuration also successfully and i tested thru run test for both JCO and IPC components all are successful. now when i tried with

  • Receiving the internal 500 error while testing java web service

    HI, Problem Summary: Receiving the internal 500 error while testing java web service in integrated weblogic server. my scenario is like, retrieve the Payload from Dehydration tables. We are connected to SOA_INFRA schema and we are retrieving the payl

  • Bluetooth keyboard/mouse

    Usually on startup, a wireless keyboard setup notice appears that my cpu search can't find a wireless keyboard. Original setup was normal and items function well but notice appears often.