Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JInternalFrame repaint() problems

Posted on 1997-11-17
4
Medium Priority
?
921 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 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