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

Painting problems w/ JScrollPane when done other than in paint(Graphics) functi

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.5, 1.2.0
    • client-libs
    • x86, sparc
    • solaris_2.5.1, windows_nt



      Name: rm29839 Date: 03/31/98


      /////////////////////////////////////////////////////////////////////////////////////////////////
      //
      // When the size of the component inside the JScrollPane is
      // more than that of the JScrollPane itself, any painting done
      // by the component paints over other components in the
      // frame (the frame that contains the scroll pane and some other
      // components). This happens only when painting is done
      // using a Graphics objects returned by getGraphics(). This
      // problem does not occur when the same painting is done
      // using the Graphics object given to paint() function.
      //
      // Here's the source code in its entirety - run it and see for yourself.
      /////////////////////////////////////////////////////////////////////////////////////////////////

      import java.applet.*;
      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;

      public class Test extends JFrame
      {
          Test(String s)
          {
              super(s);
          }

          static public void main (String []args)
          {
              Test tst = new Test("Test Application");
              tst.getContentPane().setLayout(new BorderLayout());
              tst.getContentPane().add("East", new JButton ("East"));
              tst.getContentPane().add("West", new JButton ("West"));
              tst.getContentPane().add("North", new JButton ("North"));
              tst.getContentPane().add("South", new JButton ("South"));
              tst.getContentPane().add(new MyScrollPane());
              tst.setSize(640, 480);
              tst.show();
          }
      }

      class MyScrollPane extends JScrollPane
      {
          MyScrollPane()
          {
      super (new Contained());
          }
      }

      class Contained extends JComponent implements MouseMotionListener
      {
      Contained()
      {
      addMouseMotionListener(this);
      }
          public Dimension getMaximumSize()
          {
      return new Dimension(1500, 1500);
          }
          public Dimension getMinimumSize()
          {
      return new Dimension(1500, 1500);
          }
          public Dimension getPreferredSize()
          {
      return new Dimension(1500, 1500);
          }
      public void mouseDragged(MouseEvent e)
      {
      Graphics g;
      g = getGraphics();
      Point point;
      point = e.getPoint();
      // repaint();
      display_mouse_coordinates(g, point);
      }
      public void mouseMoved(MouseEvent e)
      {
      Graphics g;
      g = getGraphics();
      Point point;
      point = e.getPoint();
      // repaint();
      display_mouse_coordinates(g, point);
      }
      void display_mouse_coordinates(Graphics g, Point point)
      {
              String s;
      s = point.x + ", " + point.y;

              Dimension dimWin = getSize();
              Insets insFrame = getInsets();
              int nWinWidth = dimWin.width - (insFrame.left + insFrame.right);
              int nWinHeight = dimWin.height - (insFrame.top + insFrame.bottom);

      g.setColor(Color.white);
              g.fillRect(0, 0, nWinWidth, nWinHeight);
      g.setColor(Color.black);
      g.drawString(s, point.x, point.y);
      }
      }
      (Review ID: 26665)
      ======================================================================

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: