JTree Refesh problem

Hello --
I've searched this subject ad nauseum on these forums and the rest of the web, and I'm still coming up blank.
Basically, I have a file structure JTree. To do a "refresh" view, I basically kill the original object, and rebuild it again -- while first storing the last TreePath the user was on.
Since this tree is built dynamically, placeholders are used to tell if the parent node has any children. From there, it looks up its children.
During the refresh, I fire the tree.expandPath(path), and in my expansion listener, it should take care of the rest.
Well, it seems like all the steps are going correctly, due to the debug output I'm getting, but I can't get the tree to scroll to the path. Here's the reload part:
public void refreshTree(TreePath path){
   TP tp = null;
   Object [] obj = path.getPath();
     for (int i = 2; i <= obj.length; i++){
          tp = new TP(obj, i);     
         tree.expandPath(tp.getTP());
//I've tried these in the for loop to no avail
//               tree.setSelectionPath(tp.getTP());
//              tree.scrollPathToVisible(tp.getTP());
       //this should be the last and final TreePath object
     tree.expandPath(tp.getTP());
     //tree.getSelectionModel().setSelectionPath(tp.getTP());
          tree.setSelectionPath(tp.getTP());
     tree.scrollPathToVisible(tp.getTP());
     //this class exists so I can build the treepath one
        //leaf at a time
     class TP extends TreePath{
          public TP(Object[] obj, int length){
               super(obj, length);     
          public TreePath getTP(){
               return this;
     }I've tried rebuild and all, and it seems like everything is doing what it's supposed to except drawing it right. Here's the code for the expansion:
class selectionListener implements TreeExpansionListener{
   public void treeExpanded(TreeExpansionEvent evt){
     DefaultMutableTreeNode node = getTreeNode(evt.getPath());
     TreeNode firstBorn = node.getFirstChild();
     if (firstBorn.toString().equals(PLACEHOLDER)){
          System.out.println("made it");  //debug
          populateTree(evt.getPath());  //this gets the new stuff
  public void treeCollapsed(TreeExpansionEvent evt){}          
}So, again, it seems like everything is firing the way it should, it's just not redrawing the tree to the current path.
I'm on Java 1.4[02], Windows 2K, and JTree is set to SINGLE selection mode. If you need any additional information, please let me know.
Thank you very much for your time.
-Steve

It seems that the tree is firing a node change itself, because I have code executing in the
public void treeExpanded(TreeExpansionEvent evt)
function.
I also put a bit of debug code in... I have
System.out.println("Is collapsed? " + tree.isCollapsed(tp.getTP()));
Inside my for loop... the output is false everytime.
So it seems that everything exists, it's just not repainting the gui for some reason or other. I'm not spinning off seperate threads to do anything, so I'd assume it's not a thread problem.
Any ideas? This is really getting frustrating, for something I thought would be so simple.

Similar Messages

  • JTree Inserting Problem

    Please help me ..
    i have write a code ..which is when the user clicks the button...
    a jtree table will come and the values inside the jtree will be filled by the contents of the selected items in the form...
    but my problem is jtree only is comming
    i created the object class ... but ...
    the initialisation is not happening...
    plz check the code below .. this is my class
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class Reservation extends JFrame implements ItemListener,ActionListener{
         JComboBox fromCity = null;
         JComboBox toCity = null;
         JComboBox dDay = null;
         JComboBox dMonth = null;
         JComboBox dYear = null;
         JComboBox rDay = null;
         JComboBox rMonth = null;
         JComboBox rYear = null;
         JComboBox adult = null;
         JComboBox Cabin = null;
         JFrame table;
         public Reservation()
              setSize(600,400);
              JPanel p = new JPanel();
              //getContentPane().setLayout(new BorderLayout());
              GridBagLayout gbl = new GridBagLayout();
              GridBagConstraints gbc = new GridBagConstraints();
              p.setLayout(gbl);
              String []cities = {"New York","Chicago","Miami","Pittsburgh","Memphis","New Orleans"};
              String [] days={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","27","28","29","30","31"};
              String [] months = {"January","Feburary","March","April","May","June","July","August","September","October","November","December"};
              String [] year = {"2006","2007"};
              String [] adt = {"1","2","3","4"};
              String [] cab = {"Buisness","Economy"};
              fromCity = new JComboBox(cities);
              fromCity.setSelectedIndex(0);
              toCity = new JComboBox(cities);
              toCity.setSelectedIndex(0);
              dDay = new JComboBox(days);
              dMonth = new JComboBox(months);
              dYear = new JComboBox(year);
              rDay = new JComboBox(days);
              rMonth = new JComboBox(months);
              rYear = new JComboBox(year);
              adult = new JComboBox(adt);
              Cabin = new JComboBox(cab);
              JLabel frmCity = new JLabel("From");
              frmCity.setLabelFor(fromCity);
              JLabel tCity = new JLabel("To");
              tCity.setLabelFor(tCity);
              JLabel dDate = new JLabel("Departure Date");
              dDate.setLabelFor(dDate);
              JLabel rDate = new JLabel("Return Date");
              rDate.setLabelFor(rDate);
              JLabel Psg = new JLabel("Pasengers");
              Psg.setLabelFor(Psg);
              JLabel Adults = new JLabel("Adults");
              Adults.setLabelFor(Adults);
              JLabel cabin = new JLabel("Cabin");
              cabin.setLabelFor(cabin);
              JLabel search = new JLabel("Search By");
              search.setLabelFor(search);
              JRadioButton ROneWay = new JRadioButton("One Way");
              JRadioButton RRoundTrip = new JRadioButton("Round Trip");
              JButton searchbutton = new JButton("Date");
              ButtonGroup group = new ButtonGroup();
              group.add(ROneWay);
              group.add(RRoundTrip);
              gbc.gridx = 0;
              gbc.gridy = 0;
              gbc.insets = new Insets(0,30,0,0);
              p.add(frmCity,gbc);
              gbc.gridx =1;
              gbc.gridy = 0;
              gbc.insets = new Insets(0,30,0,0);
              p.add(fromCity,gbc);
              gbc.gridx =0;
              gbc.gridy = 1;
              gbc.insets = new Insets(0,30,0,0);
              p.add(tCity,gbc);
              gbc.gridx =1;
              gbc.gridy = 1;
              gbc.insets = new Insets(10,30,0,0);
              p.add(toCity,gbc);
              gbc.gridx = 0;
              gbc.gridy = 2;
              gbc.insets = new Insets(10,50,0,0);
              p.add(ROneWay,gbc);
              gbc.gridx = 1;
              gbc.gridy = 2;
              gbc.insets = new Insets(10,30,0,0);
              p.add(RRoundTrip,gbc);
              gbc.gridx = 1;
              gbc.gridy = 3;
              gbc.insets = new Insets(0,0,0,0);
              p.add(dDate,gbc);
              gbc.gridx = 0;
              gbc.gridy = 4;
              p.add(dDay,gbc);
              gbc.gridx = 1;
              gbc.gridy = 4;
              p.add(dMonth,gbc);
              gbc.gridx = 2;
              gbc.gridy = 4;
              p.add(dYear,gbc);
              gbc.gridx = 1;
              gbc.gridy = 5;
              gbc.insets = new Insets(0,0,0,0);
              p.add(rDate,gbc);
              gbc.gridx = 0;
              gbc.gridy = 6;
              p.add(rDay,gbc);
              gbc.gridx = 1;
              gbc.gridy = 6;
              p.add(rMonth,gbc);
              gbc.gridx = 2;
              gbc.gridy = 6;
              p.add(rYear,gbc);
              gbc.gridx = 1;
              gbc.gridy = 7;
              p.add(Psg,gbc);
              gbc.gridx = 0;
              gbc.gridy = 8;
              p.add(Adults,gbc);
              gbc.gridx = 1;
              gbc.gridy = 8;
              p.add(adult,gbc);
              gbc.gridx = 0;
              gbc.gridy = 9;
              p.add(cabin,gbc);
              gbc.gridx = 1;
              gbc.gridy = 9;
              gbc.insets = new Insets(10,0,0,0);
              p.add(Cabin,gbc);
              gbc.gridx = 0;
              gbc.gridy = 10;
              p.add(search,gbc);
              gbc.gridx = 1;
              gbc.gridy = 10;
              gbc.insets = new Insets(10,0,0,0);
              p.add(searchbutton,gbc);
              getContentPane().add(p);
              fromCity.addItemListener(this);
              toCity.addItemListener(this);
              dDay.addItemListener( this);
              dMonth.addItemListener( this);
              dYear.addItemListener(this);
              adult.addItemListener(this);
              Cabin.addItemListener(this);
              searchbutton.addActionListener(this);
              //Jtable form
              table = new JFrame();
              Container container;
              container = table.getContentPane();
              JPanel jpanel = new JPanel(new GridLayout(2,1));
              container.setLayout(new GridLayout(2,1));
              JLabel l1 = new JLabel("Departure Journey");
              l1.setLabelFor(l1);
              container.add(l1);
              final String[] colHeads = {"","Flightno","Date","Departure Time","Arrival Time","Flight","Duration","Fare"};
              final Object[ ][ ] data = new Object[10][10];
              JTable table = new JTable(data,colHeads);
              int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;     
              int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
              JScrollPane jsp = new JScrollPane(table,v,h);
              container.add(jsp,BorderLayout.CENTER);
         String ffcity,ttcity,dday,dmon,dyear,adt,cab;
         public void itemStateChanged(ItemEvent e)
              ffcity = (String)fromCity.getSelectedItem();
              ttcity = (String)toCity.getSelectedItem();
              dday = (String)dDay.getSelectedItem();
              dmon = (String)dMonth.getSelectedItem();
              dyear = (String)dYear.getSelectedItem();
              adt = (String)adult.getSelectedItem();
              cab = (String)Cabin.getSelectedItem();
         public void actionPerformed(ActionEvent ae)
         if(ae.getActionCommand() == "Date")
              try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection con = DriverManager.getConnection("jdbc:odbc:ds","sa", "");
              PreparedStatement stmt = con.prepareStatement("select ifno,vdtime,vatime,vdate1,vdate2,vdate3,efare from airways where fcity = ? and tcity = ? and vdate1 = ? and vdate2 = ? and vdate3 = ?");
              stmt.setString(1,ffcity);
              stmt.setString(2,ttcity);
              stmt.setString(3,dday);
              stmt.setString(4,dmon);
              stmt.setString(5,dyear);
              ResultSet d = stmt.executeQuery();
              /* int count=0;
              while(d.next())
              {count++;
              int i = 0;*/
              while(d.next())
              /*for(int j =1;j<=7;j++)
              data[i][j] = rs.getString(j);
              System.out.println(" " + data[i][j]);
              }i++;*/
              System.out.println(d.getInt(1));
              System.out.println(d.getDouble(2));
              catch(Exception ex)
                   System.out.println("Error occurred");
                   System.out.println("Error:"+ex);
              table.setVisible(true);
              table.setSize(300,200);
         private static void createAndShowGUI()
              JFrame.setDefaultLookAndFeelDecorated(true);
              Reservation r=new Reservation();
              JFrame frame = new JFrame("Reservation Form");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //r.pack();
              r.setVisible(true);
         public static void main(String[] args)
              SwingUtilities.invokeLater(new Runnable(){
                   public void run()
                        createAndShowGUI();
    in this object creation is not happening
    when i run this code ...
    only jtree is comming..
    how can i make it the values of seceted items to come in table
    i commented the parts that having error..
    when u uncomment it u will get the problem of this code

    please anyone

  • JTree selection problem when using custom renderer and editor

    Hello:
    I created a JTree with custom renderer and editor.
    The customization makes JCheckBox to be the component
    responsible for editing and rendering.
    The problem is that when I click on the node with the checkbox
    the JTree selection model does not get updated.
    Without customizations of the editor and renderer the MouseEvent would be fired and BasicTreeUI$MouseHandler.mousePressed() method would call
    the selectPathForEvent() method which would be responsible for updating
    the selection model. At the same time if I attach a mouse listener to the JTree (customized) I see the events when clicking on the nodes. It seems like the MouseEvent gets lost and somehow as a result of which the selection model does not get updated.
    Am I missing something?
    Thanks
    Alexander

    You probably forgot to call super.getTreeCellRendererComponent(...) at the beginning of your getTreeCellRendererComponent(...) method in your custom renderer.
    Or maybe in the getTreeCellEditorComponent(...) of the TreeCellEditor...

  • JTree Repaint Problem .

    I'm creating a dynamic JTree by querying th DB. The JTree has to reflect the changes if any.
    But the problem is that although I'm getting all the correct nodes in the JTree, the tree display is not repainted if the window is maximized or focussed and the tree area is displayed grey. Other components like buttons etc are correctly visible.
    If I click in the greyed area of the JTree then that particular node is visible and the rest nodes are hidden.
    same problem comes when I have a JPopup for the nodes.. It leaves a greyed rectangle in place of the JPopup.
    Any suggestions will be a great help.
    - Praveen

    I tried the reload , revalidate and the repaint method of the Treemodel, but nothing changed... its all the same.I'd like to explain in full what am I doing.
    I have some items in the DB which are shown in the JTree. When any Item is added to the DB I poll the DB
    after an interval to check new entries or deleted entries, and this is to be updated to the JTree.
    The additions and deletions are going on properly a/c to the DB the only problem being that , that if the window(JFrame) containing the JTree (JTree is contained in JScrollPane) is minimized or hidden, then only the JTree is greyed and not the other components such as the buttons.
    Interestingly if I double click in the JTree area then the Jtree becomes visible properly. This happens after each update of the JTree.
    Hope this description will give a better view.
    Thanks for all your previous helpful hints.

  • JTree selection problem

    I have a problem trying to select a node of a JTree using JDK 1.3.1 and JDK 1.4 beta 3. I use a JTree with a DefaultTreeModel and DefaultMutableTreeNodes.
    Before the tree became visible it has all the nodes loaded but not visible. Then I want to select a path of the tree using a node (DefaultMutableTreeNode) but I not able to do it.
    The path isn't selected and isn't visible.
    I use the following code:
      jTree.setExpandsSelectedPaths(true)
      jTree.setSelectionPath(new TreePath(node.getPath()));
      //I've also tried with
      jTree.expandPath(new TreePath(dmtn.getPath()));Thanks.

    Fair enough. I guess I need to do a bit more reading.
    You have to create a new TreePath object because the
    getPath() method of DefaultMutableTreeNode returns an
    array of TreeNodes where as the setSelected method of
    JTree requires a TreePath object.
    Why are you creating a new path with the contents ofa
    call to getPath?
    wouldn't node.getPath() be what you want toexpend/set
    visible/scroll to etc
    try it without creating a new TreePath

  • 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.

  • JTree, strange problem

    I created a JTree on top of a DefaultMutatableTreeNode by using the constructor JTree(TreeNode root)
    I tried removing all leaf nodes of the model, using node.removeFromParent(). And unsurprisingly the UI is automatically updated.
    After that, i reinsert new leaf nodes(they are new instances having new physical address) into the model, using parent.add(node). And unsurprisingly, the UI is automatically updated. The JTree looks powerful at the moment, i am quite satisfied with it.
    However the nightmare comes, when i click on the leaf nodes on the UI and the getLastSelectedPathCompoent() mystically returned the already-removed leaf nodes but not the newly-inserted leaf nodes.
    I tried debugging for a couple of hours, but failed! I think i am doing something really wrong :( Anyone help me out? Thanks a lot!

    problem solved:)
    solved by calling the updateUI() for the removal operation.....

  • JTree renderer problem

    I have listed below a shor example.
    What I need is a method to do each cell to be as wide as the tree is (see the red border line), even if I resize the window. And ofcourse, the tree should keep a minimum width so every cell is fully shown.
    I'll be waiting for your answers. Thanks.
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.*;
    public class TreeExample extends JFrame {
        public TreeExample() {
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            getContentPane().add(new JScrollPane(new SomeTree()));
            pack();
        public static void main(String[] args) {
           SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new TreeExample().setVisible(true);
    class SomeTree extends JTree {
        public SomeTree() {
            DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
            String str = "***";
            for (int i = 0; i < 10; i++) {
                root.add(new DefaultMutableTreeNode(str));
                str += "***";
            setModel(new DefaultTreeModel(root));
            setCellRenderer(new SomeCellRenderer());       
            setBorder(BorderFactory.createLineBorder(Color.RED));
    class SomeCellRenderer extends JLabel implements TreeCellRenderer {
        public Component getTreeCellRendererComponent(JTree tree, Object value,
                                                          boolean selected, boolean expanded,
                                                          boolean leaf, int row,
                                                          boolean hasFocus) {
            setOpaque(true);
            setText(value.toString());
            setBackground(Color.LIGHT_GRAY);
            return this;
    }

    The only problem i can figure is maybe the layout. Flowlayout is squeezing the size of the buttons so that they can appear in the little area that they do get. If you use borderlayout instead of the flowlayout, it may solve your problem. If that also doesn't work then set the minimum sizes of the labels.

  • Jtree casting problem

    Hi ,
    I am new to java swings, I am having problem with jtree casting.
    I have the tree which I created in the similar way as DNDTree
    The tree has 4 types such as model/subject/entity/attribues each
    of different class. My problem is when I drag and drop .. later I have
    to save the tree with all the properties into respective tables. Please
    help me how do I accomplish.
    Thanks

    Hi, This is the error I m getting.
    Excpetion is javax.swing.tree.DefaultMutableTreeNode cannot be cast to com.idecisions.cdi.hme_prac.MySubjectNodejava.lang.ClassCastException: javax.swing.tree.DefaultMutableTreeNode cannot be cast to com.idecisions.cdi.hme_prac.MySubjectNode
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)

  • JTree Printing Problem

    I am having a problem printing a JPanel that includes a JLabel, a JPanel, and a JTree. If I only add the JLabel and JPanel to the JPanel to be printed, everything works fine. But as soon as I add my JTree (which is small, and should fit on one page), the pageIndex stops being incremented and I end up with the print method being infinitely called. Has anyone run into this problem before? Why is the pageIndex not being incremented?
    Thanks for any help!
    andrewwi1

    Ok, after a whole lot of trial and error I think I answered my own question.
    It seems that adding the JTree to the Panel to be printed really caused the Print API to call the print method many many times on the same pageIndex. I had never seen it need to render the same page more than 4 or 5 times before now. I was running the code through debug (using VisualAge for Java), and was also causing the panel to be printed to the screen via JFrame. So after I'd get about 30 JFrames containing my print panel I'd assume something was wrong and kill the thread. Turns out it needs to render the same page 30+ times with a JTree (or at least with my JTree). After turning of the JFrame visibility (so I wouldn't see them pop up on my screen) and waiting for quite awhile, the page finally printed just fine.

  • JTree accessibility problem?

    I've got an application which uses a JTree to display the data and cannot get a screen reader to speak any of the nodes as I navigate to them with the mouse or by the keyboard. I've used javaferret and indeed, it shows that no accessible name or description is getting set as I navigate around. Is this a problem with the JTree itself or a problem with the access bridge? Is there any way for me to diagnose this problem?

    I'm using the default cell renderer. I've verified that I can reproduce the problem with simple examples from the tutorials. Here's a bit of code that I'm currently using to reproduce. It turns out that JAWS always reads the node you left rather than the node you were entered....apparently the active descendent isn't being updated properly...
    import javax.accessibility.*;
    import java.beans.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.tree.*;
    * Tree View!
    * @author Jeff Dinkins
    public class TreeTest extends JPanel implements PropertyChangeListener
    public static void main(String[] args)
    TreeTest p = new TreeTest();
    JFrame f = new JFrame("Test JTree Accessibilty");
    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(BorderLayout.NORTH, p);
    f.pack();
    f.setVisible(true);
    public TreeTest() {
    setLayout(new BorderLayout());
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("Music");
    DefaultMutableTreeNode catagory;
    DefaultMutableTreeNode composer;
    DefaultMutableTreeNode style;
    DefaultMutableTreeNode album;
    // Classical
    catagory = new DefaultMutableTreeNode("Classical");
    top.add(catagory);
    // Beethoven
    catagory.add(composer = new DefaultMutableTreeNode("Beethoven"));
    // Brahms
    catagory.add(composer = new DefaultMutableTreeNode("Brahms"));
    // Mozart
    catagory.add(composer = new DefaultMutableTreeNode("Mozart"));
    catagory.add(composer = new DefaultMutableTreeNode("Schubert"));
    // Jazz
    top.add(catagory = new DefaultMutableTreeNode("Jazz"));
    // Ayler
    catagory.add(composer = new DefaultMutableTreeNode("Albert Ayler"));
    // Chet Baker
    catagory.add(composer = new DefaultMutableTreeNode("Chet Baker"));
    // Coltran
    catagory.add(composer = new DefaultMutableTreeNode("John Coltrane"));
    // Miles
    catagory.add(composer = new DefaultMutableTreeNode("Miles Davis"));
    // Rock
    top.add(catagory = new DefaultMutableTreeNode("Rock"));
    // The Beatles
    catagory.add(composer = new DefaultMutableTreeNode("The Beatles"));
    // Crowded House
    catagory.add(composer = new DefaultMutableTreeNode("Crowded House"));
    // Harvin Garvel
    catagory.add(composer = new DefaultMutableTreeNode("Harvin Garvel"));
    // The Steve Miller Band
    catagory.add(composer = new DefaultMutableTreeNode("Steve Miller Band"));
    JTree tree = new JTree(top);
    add(new JScrollPane(tree), BorderLayout.CENTER);
    tree.getAccessibleContext().addPropertyChangeListener(this);
    public void propertyChange(PropertyChangeEvent e)
    String name = e.getPropertyName();
    if (AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY.equals(name))
    System.out.println("active descendant changed");
    AccessibleContext oldAC = (AccessibleContext)e.getOldValue();
    String old = (oldAC == null) ? null : oldAC.getAccessibleName();
    System.out.println("old descendant is " + old);
    AccessibleContext ac = (AccessibleContext)e.getNewValue();
    System.out.println("new descendant is " + ac.getAccessibleName());

  • JTree Render Problem

    Hi!
    In my application I have a JTree component, wich has nodes and childs. When the application starts up I populate the JTree with some data retrieved from a database. But after that I need to change some data in the database wich is reloaded and this changes the text inside the nodes in the JTree. Then I call the repaint() method of the JTree update. The problem is when the updated string is bigger then the old string, part of the string is not visible i.e it shows "..." after the text.
    Is there someone who knows this problem?
    Thanks in advance.

    Hi dayanandabv ! Thanks for your reply ! I tried your suggestion, but it won't work! i tried validate() afler and before the repaint method.
    Any other ideas?
    I'm trying hard to fix this but with no results :( some help will be appreciated.
    Thanks again.

  • JTree update problem

    Hi,
    I have created a JTree using the vector constructor. The hierachy is a teamList(Vector) -> team(Vector) -> players(Object). I put the teamList into the JTree construcotr.
    At various points in the program the user can add teams to the team list, or players to an existing team. This is no problem. However the JTree does not update when the structure is changed.
    I have found that it is updated if the tree isnt expanded, but once expanded it doesnt get updated. I have tried calling treeDidChange(), revalidate() and loads of other methods which sound like they might do the trick! but no success. I'm sure there must be a way of doing this and that I'm just missing the point!
    Do I need to add the data to the vectors some other way? Any suggestions are greatfully received. I've spent far too long on this already!

    What about separating the UI from the program logic and data? Perhaps the JTree shouldn't hold the data, just a representation of the data.

  • JTree.clearToggledPaths problem

    I was having a problem with a JTree holding on to references of nodes after removing them which was fixed with a call to clearToggledPaths(). However, it clears all toggled paths and the whole tree is set to unexpanded afterwards. I don't want this.
    There is a removeDescendantToggledPaths(Enumeration<TreePath> toRemove) method, but I don't know how to find the TreePath when given a TreeNode. What obvious solution am I mission?
    Thanks!

    Since you did double post, the least you can do is point to the new thread so we don't have discussions going on in two different threads:
    http://forum.java.sun.com/thread.jspa?threadID=751064&tstart=0

  • JTree collapse problem

    hi all
    i have a jtree contains where users can edit text in nodes....
    when user finshes editing i want to display the new text keeping the edited node expanded...
    all things i have done either make the whole tree collapse or makes the text appear as '.....' instead of what the user has entered..
    thnx in advance

    Sandra,
    I fetch data from a database and show it in a JTree.
    Because I have to refresh the tree everytime a node is
    expanded I had to overwrite the default expand()
    method.why do you have to refresh the tree? can you pls explain...
    Now in expand() I fetch the data, build a new
    tree and fire treeStructureChanged(rootNode) and make
    then a call to super.expand(path). This works fine,
    but now the tree doesn't know which node is expanded
    and which is not and it always trys to expand a node
    even if it is already expanded. this sounds horrendous and way to much. why do you need to build a new tree every time?
    Maybe somebody had the same problem and/or can help
    me?i have written many trees (so to speak ;) which dynamically load data from DBs. so there are my 2 cents:
    1) don't overwrite methods of JTree, it is not necessary (in most cases) and way to complex, interfering with the tree model et al
    2) if you use the appr. classes (DefaultTreeModel, DefaultMutableTreeNode, etc) most things are achieved by firing the appr. events (if not done already by those classes).
    3) in most cases you only will need a custom cell renderer to show the data in a way you like/need.
    send some more details of your problems, maybe there are other/more efficient ways of achieving your goals.
    thomas

Maybe you are looking for

  • Help me in bdc

    Hi frnd...     i hav a doubt in bdc that when we go for call transaction or session method for inserting data into respective tables, we come through errors. so can anyone help me how to handle error. so we say that we delete successful records and r

  • Windows Small Business Server 2008 c000021a 0x00000000 wusa

    Good day (well hopefully it improves...), I initially got a BSOD 0xc00000f which chkdsk sorted then I ran into 0xc000000f which I got around by restoring backup hives.  0xc000000d was in there somewhere as well which, if I remember this whole process

  • JQuery Mobile with Dreamweaver CS6 - Blink

    I´ve created a JQuery Mobile page using Dreamweaver CS6  that works perfectly in Firefox, but in iPad it appears blink effect when there´s a transition. How to remove blink in transitions for JQuery Mobile ?

  • Can't connect to a specific wifi network

    Hello, please, someone can help me? (sorry for my poor english, not native) First of all, i's important to say that I could connect normally to this network before, and then suddenly it stopped connecting. I can say it's a problem with my device, 'ca

  • Workflow visio error

    Hi , I m working with MDM SP05 worflow.Initially whenever i create a workflow the stencils are visible ,I can save the workflow.Whenever I exit it and again open it i get all other stencils apart from workflow stencil..Why is this instability? Any su