?
Solved

JInternalFrame repaint() problems

Posted on 1997-11-17
4
Medium Priority
?
928 Views
Last Modified: 2008-02-26
I have a JTree in a JInternalFrame and when the tree is clicked (i.e. expanded or collapsed), it does not get repainted. It behaves normally when used in a regular Frame. I've tried manually calling repaint() in the event handler of the tree mouse clicks - that didn't work either. Only when I drag, move or resize the JInternalFrame does the JTree get updated. Any ideas????
..................Lee
lee_kleiner@sns.ca
0
Comment
Question by:leeor
  • 2
4 Comments
 
LVL 4

Expert Comment

by:rembo
ID: 1230745


Trying calling invalidate() on the Tree in the
mouse click event handler.  

If you then validate() the tree again, the
tree should redraw.


0
 

Author Comment

by:leeor
ID: 1230746
That did not work....

0
 
LVL 1

Accepted Solution

by:
mnelson051997 earned 400 total points
ID: 1230747
I have not had a problem.  Here is some of my sample code for
building a simple tree and putting it is a JInternalFrame.
It works both with and without the scroll pane.

import com.sun.java.swing.*;
import com.sun.java.swing.tree.*;
import java.awt.*;

public class MyFrame extends JFrame
{
   public MyFrame()
   {
      setTitle( "JTree0" );
     
      // Store the content pane in a variable for easier access.

      JPanel contentPane = (JPanel)getContentPane();
      contentPane.setBackground( Color.lightGray );

      // Components will all be added to this panel.

      contentPane.setLayout( new BorderLayout() );

      DefaultMutableTreeNode root =
                  new DefaultMutableTreeNode( "President/CEO" );

      DefaultMutableTreeNode vp =
                  new DefaultMutableTreeNode( "Sales Vice-President" );
   
      DefaultMutableTreeNode drone =
                  new DefaultMutableTreeNode( "Sales Guy 1" );
      vp.add( drone );
      drone = new DefaultMutableTreeNode( "Sales Guy 2" );
      vp.add( drone );
      drone = new DefaultMutableTreeNode( "Sales Guy 3" );
      vp.add( drone );
     
      root.add( vp );
                 
      vp = new DefaultMutableTreeNode( "Development Vice-President" );
   
      drone = new DefaultMutableTreeNode( "Nerd 1" );
      vp.add( drone );
      drone = new DefaultMutableTreeNode( "Nerd 2" );
      vp.add( drone );
      drone = new DefaultMutableTreeNode( "Nerd 3" );
      vp.add( drone );
                 
      root.add( vp );
     
      JTree tree = new JTree( root );
     
      JScrollPane scroller = new JScrollPane( tree );
     
      JInternalFrame inFrame = new JInternalFrame( "Ok" );
      inFrame.setBounds( 50, 50, 200, 200 );
      inFrame.getContentPane().add( "Center", scroller );
     
      JDesktopPane desktop = new JDesktopPane();
      contentPane.add( "Center", desktop );
      desktop.add( inFrame );
   }

}
0
 

Author Comment

by:leeor
ID: 1230748
I got it working thanks 2 your source code...Thanks

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question