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

DefaultDesktopManager does not paint correctly dragged out JInternalFrames

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"


      A DESCRIPTION OF THE PROBLEM :
      DefaultDesktopManager in Java 6 does not repaint correctly a JInternalFrame drawn in its dragFrameFaster method if the JInternalfFrame was previously outside of the visible rect of the JDesktopPane. It appears the problem is because the dragFrameFaster method is always assuming that the intersection between the previous bounds and the visibleRect of the JDesktopPane will always return positive width and height. This is not the case. See this collaboration thread for futher analysis and the discovery of the bug:
      https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=14426&forumID=1463

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this test, drag the JInternalFrame outside of the JDesktopPanes visible area and drag it back. Do this until you see the drawing error.

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


      public class DefaultDesktopManagerTest implements Runnable{

          JInternalFrame jif;
          public void run(){
              JDesktopPane jdp = new JDesktopPane2();
              jdp.setSize(1000,1000);
              JScrollPane jsp = new JScrollPane(jdp);
              JFrame jf = new JFrame();
              jf.add(jsp);
              jif = new JInternalFrame();
              jif.add(new JLabel("Hi"));
              jif.setSize(100,100);
              jdp.add(jif);
              jif.setVisible(true);
              jf.setSize(400,400);
              jf.setVisible(true);
              System.out.println(jdp.getSize());
          }

          class JDesktopPane2 extends JDesktopPane implements Scrollable{

      public Dimension getPreferredSize(){ return getSize(); }

              public Dimension getPreferredScrollableViewportSize(){
                  return getSize();
              }

              public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction){
                  return (orientation == SwingConstants.VERTICAL) ? visibleRect.height : visibleRect.width;
              }

              public boolean getScrollableTracksViewportHeight(){
      if (getParent() instanceof JViewport) {
                      Dimension psvps = getPreferredScrollableViewportSize();
      return (((JViewport)getParent()).getHeight() > psvps.height);
      }
      return false;
              }

              public boolean getScrollableTracksViewportWidth(){
      if (getParent() instanceof JViewport) {
                      Dimension psvps = getPreferredScrollableViewportSize();
      return (((JViewport)getParent()).getWidth() > psvps.width);
      }
      return false;
              }

              public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction){
                  return (orientation == SwingConstants.VERTICAL) ? visibleRect.height : visibleRect.width;
               }

          }


          public static void main(String ... args){
              SwingUtilities.invokeLater(new DefaultDesktopManagerTest());
          }

      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The JInternalFrame should be drawn correctly.
      ACTUAL -
      Odd visuals within the JInternalFrame

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;


      public class DefaultDesktopManagerTest implements Runnable{

          JInternalFrame jif;
          public void run(){
              JDesktopPane jdp = new JDesktopPane2();
              jdp.setSize(1000,1000);
              JScrollPane jsp = new JScrollPane(jdp);
              JFrame jf = new JFrame();
              jf.add(jsp);
              jif = new JInternalFrame();
              jif.add(new JLabel("Hi"));
              jif.setSize(100,100);
              jdp.add(jif);
              jif.setVisible(true);
              jf.setSize(400,400);
              jf.setVisible(true);
              System.out.println(jdp.getSize());
          }

          class JDesktopPane2 extends JDesktopPane implements Scrollable{

      public Dimension getPreferredSize(){ return getSize(); }

              public Dimension getPreferredScrollableViewportSize(){
                  return getSize();
              }

              public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction){
                  return (orientation == SwingConstants.VERTICAL) ? visibleRect.height : visibleRect.width;
              }

              public boolean getScrollableTracksViewportHeight(){
      if (getParent() instanceof JViewport) {
                      Dimension psvps = getPreferredScrollableViewportSize();
      return (((JViewport)getParent()).getHeight() > psvps.height);
      }
      return false;
              }

              public boolean getScrollableTracksViewportWidth(){
      if (getParent() instanceof JViewport) {
                      Dimension psvps = getPreferredScrollableViewportSize();
      return (((JViewport)getParent()).getWidth() > psvps.width);
      }
      return false;
              }

              public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction){
                  return (orientation == SwingConstants.VERTICAL) ? visibleRect.height : visibleRect.width;
               }

          }


          public static void main(String ... args){
              SwingUtilities.invokeLater(new DefaultDesktopManagerTest());
          }

      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            vdyakov Victor Dyakov
            Reporter:
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: