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

Overlapping JInternalFrames render JTable cell background color incorrectly

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0_06"
      Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
      Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When there are overlapping JInternalFrames that contain JTables that have the table cells changing color on events. The front frame does not update the cells correctly. The cells that are over another frame will redraw correctly, but the cells (or parts of cells) that are over the JDesktop do not.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create an application that has two or more JInternalFrames with JTables in them. Provide a custom cell renderer that will change the background color on an event and then change it back on another event. When the table cells are over the desktop they do not redraw correctly if the frame is partially covering another frame.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect the cells to redraw correctly.
      ACTUAL -
      The cells are not redrawn correctly.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Starting with the example here http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html#InternalFrameDemo
      replace the MyInternalFrame with
      package components;

      import java.awt.Color;
      import java.awt.Component;
      import java.util.Random;
      import java.util.Timer;
      import java.util.TimerTask;

      import javax.swing.JInternalFrame;
      import javax.swing.JTable;
      import javax.swing.SwingUtilities;
      import javax.swing.table.DefaultTableCellRenderer;

      import swing.table.DefaultMutableTableModel;

      /* Used by InternalFrameDemo.java. */
      public class MyInternalFrame extends JInternalFrame {
          static int openFrameCount = 0;
          static final int xOffset = 30, yOffset = 30;

          static Timer timer = new Timer();
          static Random random = new Random();
          private static String valueToHighlight = "apple";
          
          private static Object[][] rawData = new Object[][] {
      { "apple", new Double(".39") }, { "mango", new Double(".49") },
      { "papaya", new Double("1.19") }, { "lemon", new Double(".19") },
      { "orange", new Double(".59") },
      { "watermelon", new Double("3.19") },
      { "kiwi", new Double(".19") }, { "apple", new Double(".38") },
      { "tangerine", new Double("1.09") }};
          
          public MyInternalFrame() {
              super("Document #" + (++openFrameCount),
                    true, //resizable
                    true, //closable
                    true, //maximizable
                    true);//iconifiable

              //...Create the GUI and put it in the window...

              //...Then set the window size or call pack...
              setSize(300,300);

              //Set the window's location.
              setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
              DefaultMutableTableModel model = new DefaultMutableTableModel(rawData
           , new Object[] { "Item", "Price/lb" });
              final JTable table = new JTable(model);
              table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {

      @Override
      public Component getTableCellRendererComponent(JTable table,
      Object value, boolean isSelected, boolean hasFocus,
      int row, int column) {

      super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
      row, column);

      DefaultMutableTableModel model = (DefaultMutableTableModel)table.getModel();

      if (model.getValueAt(row, 0).equals(valueToHighlight)) {
      setBackground(Color.CYAN);
      } else {
      super.setBackground(table.getBackground());
      }

      return this;
      }
              
              });
              
              getContentPane().add(table);
              
              timer.scheduleAtFixedRate(new TimerTask() {

      @Override
      public void run() {
      final DefaultMutableTableModel model = (DefaultMutableTableModel)table.getModel();

      final int row = random.nextInt(model.getRowCount());
      valueToHighlight = rawData[random.nextInt(rawData.length)][0].toString();
      SwingUtilities.invokeLater(new Runnable() {

      @Override
      public void run() {
      model.fireTableRowsUpdated(row, row);
      }

      });
      }
              
              }, 2000, 2000);
              
          }
      }

      ---------- END SOURCE ----------

      Attachments

        Activity

          People

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Imported:
              Indexed: