Solved

JInternalFrame repaint() problems

Posted on 1997-11-17
4
891 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:

932 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

12 Experts available now in Live!

Get 1:1 Help Now