?
Solved

JInternalFrame repaint() problems

Posted on 1997-11-17
4
Medium Priority
?
911 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 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