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

Bad redraw within a lightweight container (1.1.x ONLY)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.1.2, 1.1.8
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_nt

      Description



      Name: mc57594 Date: 06/20/97


      This is a JDK 1.1.2 bug

      Components inside a lighweight container sometimes do not redraw
      at all when the container is removed and then added back to
      another container. Sometimes, the lightweight container itself
      doesn't redraw (but its contained native peer components do).

      I include a short example below to reproduce the problem. It is
      made of a lightweight container (light gray) including a native
      peer component and lightweight component.

      ---------------------- cut here --------------------------
      import java.awt.*;
      import java.awt.event.*;

      /**
       * Light container bug test case
       * <p>
       * Compile this file and run it (java LiteTest2). The following problems
       * will show up on Win32 (tested on Windows NT 4.0).
       * This was tested with the JDK 1.1.2 release on a pentium pro 200 machine.
       *
       * Adding/removing a lightweight container with a native peer doesn't
       * always redraw correctly either the lightweight components (container
       * included) or the native peer component. To reproduce the bug, simply
       * toggle the checkbox button in the example back and forth a few dozen
       * times, you'll see the redrawing bug intermitently.
       *
       * This behavior is important for any container that needs to switch
       * between different panes by removing/adding sub components (eg: TabView
       * container).
       *
       */
      public class LiteTest extends java.applet.Applet implements ItemListener
      {
      LiteContainer bottomPane;
      Label natLabel;

      public void init()
      {
      setBackground(Color.gray);
      setLayout(new GridLayout(2, 1));

      // Checkbox
      Checkbox toggleCb = new Checkbox("Remove/Add bottom pane", true);
      toggleCb.addItemListener(this);

      // Bottom container (1 label + 1 LiteComponent)
      bottomPane = new LiteContainer();
      natLabel = new Label("Native component");
      natLabel.setBackground(Color.yellow);
      LiteComponent comp = new LiteComponent();
      bottomPane.add(natLabel);
      bottomPane.add(comp);

      add(toggleCb);
      add(bottomPane);
      }

      /** Implements the ItemListener interface */
      public void itemStateChanged(ItemEvent e) {
      if (e.getStateChange() == ItemEvent.SELECTED) {
      add(bottomPane);

      // Workaround
      Point loc = natLabel.getLocation();
      natLabel.setLocation(loc.x+1, loc.y);
      natLabel.setLocation(loc.x-1, loc.y);
      }
      else {
      remove(bottomPane);
      }
      validateTree();
      repaint();
      }

      public static void main(String argv[])
      {
      LiteTest test = new LiteTest();
      test.init();

      Frame f = new Frame("Lightweight Container test");
      f.addWindowListener(test. new WinListener());
      f.add(test);
      f.setSize(600, 400);
      f.show();
      }

      public class WinListener extends WindowAdapter
      {
      public void windowClosing(WindowEvent e)
      {
      System.exit(0);
      }
      }
      }


      /**
       * A lightweight container
       */
      class LiteContainer extends Container {

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

      public void paint(Graphics g) {
      Dimension dim = getSize();
      g.setColor(getBackground());
      g.fillRect(0,0, dim.width, dim.height);

      super.paint(g);
      }

      public LiteContainer() {
      setBackground(Color.lightGray);
      setLayout(new FlowLayout());
      }
      }


      /**
       * A lightweight component (color blue)
       */
      class LiteComponent extends Component {

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

      public void paint(Graphics g) {
      g.setColor(getBackground());
      g.fillRect(0,0, getSize().width, getSize().height);
      g.setColor(Color.white);
      g.drawString("Lite component", 5, 30);
      }

      public LiteComponent() {
      setBackground(Color.blue);
      setSize(120,60);
      }
      }



      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              ibdsunw Ibd Ibd (Inactive)
              Reporter:
              mchamnessunw Mark Chamness (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: