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

Repaints are not handled correctly when JFrames are created

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.0
    • client-libs



      Name: krT82822 Date: 03/06/2000


      (please see Comments section)

      1 Mar 2000, eval1127@eng -- the effect is a PARTIAL repaint of the second row, with the MIDDLE PART
      of it selected, and with a PARTIAL "selected" state in both of the adjoining cells. This effect is somewhat hard to
      reproduce, but is most easily reproduced if you widen the enclosing frame a bit in the middle
      of the procedure described below.

      ---------------

      java version "1.3.0rc1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

      In this example, the repainting of a JTable is incorrect when a JFrame is created.

      Run the application. Select from the row menu to remove row 2. This works
      fine. Reselect the first 6 rows.

      [1 Mar 2000, eval1127@eng -- to reproduce this more consistently, I had to add the following step
      at this point: resize the JFrame to be slightly WIDER before proceeding.]

      > From the window menu, open the new frame.
      Close it. Look at the table. It repaints most of row 2, but not all. It
      should not selected at all.

      In making this app I noticed that the menu is also not displayed correctly
      after the frame comes up.

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

      public final class TableRepaintBug extends JFrame {
      JTable table;

      public static void main(String argv[]) {
      TableRepaintBug app = new TableRepaintBug();
      }
      public TableRepaintBug() {
      super("Table Repaint Bug");

      final JTextArea area = new JTextArea();
      Object[][] elements = new Object[20][5];
      Object[] columns = new Object[5];
      for (int j = 0; j < 5; j++) {
      columns[j] = new String("Column " + j);
      for (int i = 0; i < 20; i++)
      elements[i][j] = new String("Value = " + (i *
      j));
      }
      table = new JTable(elements,columns) {
      public void removeRowSelectionInterval(int i, int j) {
      System.out.println("Removing rows " + i + " - "
      + j);
      super.removeRowSelectionInterval(i,j);
      }
      };
      JScrollPane sp = new JScrollPane(table);
      table.setCellSelectionEnabled(false);
      table.setColumnSelectionAllowed(false);
      table.setRowSelectionAllowed(true);
      sp.setPreferredSize(new Dimension(400,300));

      JMenu windowMenu = new JMenu("Window");
      JMenu rowMenu = new JMenu("Row");
      Action a;
      a = new AbstractAction("Remove row 2") {
      public void actionPerformed(ActionEvent e) {
      table.removeRowSelectionInterval(2,2);
      }
      };
      rowMenu.add(a);

      a = new AbstractAction("Bring Up Frame") {
      public void actionPerformed(ActionEvent e) {
      final JFrame f = new JFrame("Close Me!");
      f.setSize(600,800);
      f.show();
      table.removeRowSelectionInterval(2,2);
      f.addWindowListener( new WindowAdapter() {
      public void windowClosing(WindowEvent
      e) {
      f.dispose();
      int[] rows =
      table.getSelectedRows();
      System.out.println("Number of
      selected rows: " + rows.length);
      for (int i = 0; i <
      rows.length; i++) {
      System.out.println(rows
      [i] + " is selected");

      }
      }
      });
      }
      };
      windowMenu.add(a);
      JMenuBar menubar = new JMenuBar();
      menubar.add(rowMenu);
      menubar.add(windowMenu);
      setJMenuBar(menubar);

      getContentPane().add(sp);
      pack();
      addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      System.exit(0);
      }
      });
      show();
      table.addRowSelectionInterval(0,5);
      }
      }
      (Review ID: 100665)
      ======================================================================

      Name: skT45625 Date: 05/09/2000


      java version "1.3.0rc1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

      When a JFrame that is covering another JFrame is removed, the JFrame that was
      being covered doesn&#8217;t paint itself. At the bottom, is an example program which
      demonstrates this. You must follow these instructions exactly to consistently
      get the bug:

      1.) Compile and run the program
      2.) You should see a frame titled &#8220;Frame 1&#8221;. Click this frame with the mouse
      once.
      3.) You should see another frame titled &#8220;Frame 2.&#8221; Close &#8220;Frame 2,&#8221; making sure
      that you do not move it
      4.) You should be able to see &#8220;Frame 1&#8221; entirely now. It should appear to be
      be &#8220;partially&#8221; painted red.

      The bug is that &#8220;Frame 1&#8221; should be entirely painted red, not partially. This
      is because &#8220;Frame 2,&#8221; which was partially obscuring it, is no longer
      over &#8220;Frame 1,&#8221; and therefore, &#8220;Frame 1&#8221; should&#8217;ve repainted itself entirely,
      with the red background color that its content pane was set to when &#8220;Frame 2&#8221;
      was activated.



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


      public class MyClass
      {
         static JFrame f1 = new JFrame("Frame 1");

         public static void main(String[] args)
         {
            f1.setSize(300,300);
            f1.addMouseListener(new MouseAdapter()
            {
               public void mouseClicked(MouseEvent e)
               {
                  createFrame2();
               }
            });
            f1.show();
         }

         static private void createFrame2()
         {
            JFrame f2 = new JFrame("Frame 2");
            f2.addWindowListener(new WindowAdapter()
            {
               public void windowActivated(WindowEvent e)
               {
                  f1.getContentPane().setBackground(Color.red);
               }
            });

            f2.setSize(300,300);
            f2.setLocation(50, 0);
            f2.setVisible(true);
         }
      }
      (Review ID: 102723)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: