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

Swing components don't repaint properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.2.1, 1.2.1_04, 1.2.2, 1.3.0, 1.3.0_02, 1.4.0
    • client-libs
    • beta
    • generic, x86, sparc
    • generic, solaris_2.6, windows_nt



      Name: krT82822 Date: 01/11/2000


      12/19/99 -- NOT reproducible with 1.2 FCS, 1.2.1 or 1.2.2 reference (green threads versions) under Solaris 2.7, so must be Solaris (native threads) specific?
      -------------
      java version "1.2.1"
      Solaris VM (build Solaris_JDK_1.2.1_04, native threads, sunwjit)

      I have a test case where a component acts like a tree branch, listening for
      mouse clicks and alternating between an open and closed state. An open state
      displays components underneath.

      However, when the branch is opened the tree doesn't appear until the window is
      resized. Once the window is resized, you can open and close the tree to your
      heart's content, until you resize while the tree is closed. Then you're back
      to the original behavior.

      Here's the code I'm working with:

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

      public class RepaintBug extends JFrame {
         public static void main(String args[]){
            new RepaintBug().show();
         }

         public RepaintBug(){
            setSize(640, 480);
            Container cp = getContentPane();
            cp.setLayout(new BorderLayout());
            FlowTreeNode ftn = new FlowTreeNode();
            ftn.addChild(new Label("Child 1"));
            ftn.addChild(new Label("Child 2"));
            ftn.addChild(new Label("Child 3"));
            ftn.addChild(new Label("Child 4"));
            ftn.addChild(new Label("Child 5"));
            cp.add(ftn, BorderLayout.CENTER);
         }
      }


      class FlowTreeNode extends JPanel {
         boolean isOpen = false;
         ImageIcon open = new ImageIcon(getClass().getResource("opennode.gif"));
         ImageIcon closed = new ImageIcon(getClass().getResource("closednode.gif"));
         Box expandedNode;
         JLabel button;
         public FlowTreeNode(){
            super(new BorderLayout());
            button = new JLabel(closed);
            add(button, BorderLayout.CENTER);
            expandedNode = Box.createVerticalBox();
            expandedNode.setVisible(false);
            add(expandedNode, BorderLayout.SOUTH);
            button.addMouseListener(new MouseAdapter(){
               public void mouseClicked(MouseEvent e){
                  if(!e.isPopupTrigger()){
                     if(isOpen){
                        button.setIcon(closed);
                        expandedNode.setVisible(false);
                        isOpen = false;
                     }
                     else{
                        button.setIcon(open);
                        expandedNode.setVisible(true);
                        isOpen = true;
                     }
                  }
               }
            });
         }

         public Component addChild(Component comp){
            return expandedNode.add(comp);
         }
      }
      (Review ID: 99108)
      ======================================================================

            tprinzing Tim Prinzing (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: