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

Moving mouse within JFrame causes button to get shown, the rest of painted stuff goes away

XMLWordPrintable

      Consider following code (in attachment, MyClipboardTest.zip):

      public class ImageTransferGUI {

          TestFrame frame1;
          JButton copy;
          Image image1;

          public ImageTransferGUI() {
             image1 = Toolkit.getDefaultToolkit().getImage((new java.io.File(System.getProperty("test.src", "."), "duke_swim.gif")).toString());
              frame1=new TestFrame(true,image1);
              System.out.println("Inside contrucor...");
              copy=new JButton("copy");
              frame1.getContentPane().add("South",copy);
              frame1.setBounds(10,350,200,200);
              frame1.setVisible(true);
          }

          public static void main(String[] args){
              new ImageTransferGUI();//.frame1.toFront();
          }

          //The frame class used in the test
          class TestFrame extends JFrame {
              boolean show;
              Image img;
              public TestFrame(boolean show,Image img){
                  this.show=show;
                  this.img=img;
              }

              public void paint( Graphics g ){
                  try {
                      if(this.show)
                          g.drawImage( this.img, 30, 30, this );
                  } catch(NullPointerException eN){}

              }
          }
      }

      Well, we have a JFrame subclass (TestFrame), and it's paint method doesn't call super.paint, so components layed out on that frame do not get shown (a button, in our case). This is OK. However, when you move mouse to the spot the button should be, the button gets visible and other painted stuff dissapears (an image, in our case).

      This is a regression. What happens with JDK 1.5.0 FCS is button gets visible when you point with mouse at it, but the drawn image stays on the frame.

      This doesn't happen with Frame component (instead of JFrame).

            ssadetsky Semyon Sadetsky (Inactive)
            vabetkin Vitalii Abetkin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: