Solved

JInternalFrame repaint() problems

Posted on 1997-11-17
4
888 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
Comment Utility


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
Comment Utility
That did not work....

0
 
LVL 1

Accepted Solution

by:
mnelson051997 earned 100 total points
Comment Utility
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
Comment Utility
I got it working thanks 2 your source code...Thanks

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now