Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4247610

Unnecessary repaint in JInternalFrame

XMLWordPrintable

    • beta
    • generic
    • generic



      Name: vi73552 Date: 06/17/99


      Damage to a underlying JInternalFrame can cause paintComponent calls to a JComponent in a JInternalFrame on top, even when that JComponent is opaque.

      Steps to reproduce -
      1) Run the sample code below
      2) Don't move any of the JInternalFrames. Just press the "Damage!" button.
      3) Examine the console output

      You will see that the JComponent on top has had a paintComponent called with a clip region equal to the intersection of its bounds and the damaged region from the underlying JInternalFrame. A JInternalFrame itself should be opaque (I can't see any value in that particular component being transparent), but even so I have made the top JComponent opaque. Thus, this paintComponent call is unnecessary. If the JComponent on top is expensive to repaint (as it is in an application of mine), this is unfortunate.

      I haven't tried this with other overlapping components to determine if this is a problem with the RepaintManager or the JDesktopPane rather than JInternalFrame.

      Here is the java version output -

      C:\>java -version
      java version "1.1.8"

      C:\>java -fullversion
      java full version "JDK1.1.8M"

      Here is the source -

      // Begin Damage.java

      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import javax.swing.*;

      public class Damage
      {
        public static void main (String[] args)
        {
          Damage d = new Damage ();
        }

        Damage ()
        {
          final JFrame frame = new JFrame ("Damage");
          JDesktopPane pane = new JDesktopPane ();
          frame.setContentPane (pane);

          JInternalFrame jif = new JInternalFrame
             ("Damager", true, true, true, true);
          InternalFramePanel ifp = new InternalFramePanel ();
          JButton damager = new JButton ("Damage!");
          ifp.add (damager);
          jif.setContentPane (ifp);
          jif.setBounds (0, 0, 300, 300);
          jif.setVisible (true);
          pane.add (jif);

          jif = new JInternalFrame ("Damagee", true, true, true, true);
          JPanel panel = new JPanel (new FlowLayout (FlowLayout.LEFT));
          final JLabel damagee = new JLabel ("");
          panel.add (damagee);
          jif.setContentPane (panel);
          jif.setBounds (60, 220, 300, 100);
          jif.setVisible (true);
          pane.add (jif);

          final Random random = new Random ();

          damager.addActionListener (new ActionListener ()
              {
                public void actionPerformed (ActionEvent event)
                {
                  damagee.setText (Integer.toString
                     (random.nextInt ()));
                }
              });

          frame.addWindowListener (new WindowAdapter ()
              {
                public void windowClosing (WindowEvent evt)
                {
                  frame.dispose ();
                  System.exit (0);
                }
              });

          frame.setSize (400, 400);
          frame.setVisible (true);
        }

        static class InternalFramePanel extends JPanel
        {
          InternalFramePanel ()
          {
            super (new FlowLayout ());
            setOpaque (true);
          }

          public void paintComponent (Graphics g)
          {
            super.paintComponent (g);
            System.out.println ("paintComponent: clip is " +
              g.getClip ());
          }
        }
      }

      // End Damage.java
      (Review ID: 84492)
      ======================================================================

            hgajewsksunw Hania Gajewska (Inactive)
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: