JDK-4178413 : Resizing swing components doesn't redraw border properly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.6,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_2.6,solaris_10
  • CPU: generic,sparc
  • Submitted: 1998-10-02
  • Updated: 2005-03-16
  • Resolved: 2005-03-16
Related Reports
Relates :  
Description
 /*
    Program to illustrate the border bug.
    
    When the window is resized to make it narrower (left to right),
    the right border does not redraw properly. When the window
    is made shorter (top to bottom), the bottom border doesn't redraw
    properly. This happens regardless of which of the four borders
    I use to resize the window. 
    
    A similar problem is described in RFE 4037592, but this is
    clearly a bug, not an RFE. 
    
    Another similar problem is described in Bug 4088352, but that
    bug only applies to JScrollPane. This bug shows up even if we
    don't use JScrollPane. Also, that bug is marked fixed. 
    
    Changing the JScrollPane and JTextArea to ScrollPane and TextArea
    fixes the problem.
    
    Changing the JFrame to Frame fixes the problem by failing to fill
    the border area.
*/

import java.awt.*;
import java.awt.event.*;

import java.util.*;

import java.text.*;

//import com.sun.java.swing.*;
//import com.sun.java.swing.event.*;

import javax.swing.*;
import javax.swing.event.*;

public class BorderBug extends JPanel
{
    public static void main(String[] args)
    {
        JFrame mf = new JFrame("Border Bug")
        {
            public Insets getInsets()
            {
                final int inset = 15;
                Insets old = super.getInsets();
                return new Insets(
                    old.top + inset, 
                    old.left + inset, 
                    old.bottom + inset, 
                    old.right + inset);
            }
        };
        mf.addWindowListener(new WindowAdapter()
            {
                public void windowClosing(WindowEvent evt)
                {
                    System.exit(0);
                }
            }
        );
        BorderBug theBug = new BorderBug();
        Container contentPane = mf.getContentPane();
        contentPane.add(theBug);
        
        mf.setBounds(10, 10, 600, 200);
        mf.show();
    }
    
    BorderBug()
    {
        super();
        setLayout(new BorderLayout());
        
        JScrollPane    scroller = new JScrollPane();
        JTextArea    theText = new JTextArea();
        theText.setLineWrap(true);
        theText.setWrapStyleWord(true);
        theText.setEditable(true);

//        Replacing these two lines with the third doesn't help
        scroller.getViewport().add(theText);
        add (scroller, BorderLayout.CENTER);
//        add (theText, BorderLayout.CENTER);
    }
}

Comments
EVALUATION Overiding in the insets in the manner of this example is slightly dubious. Anyway, this is happening because JFrame overrides paint and DOES NOT fill in the background as Frame does. I'm not sure why swing doesn't do the same, but we should. scott.violet@eng 1999-09-20 Name: pzR10082 Date: 05/03/2000 The easiest way to do this is not to override update() in JFrame. ###@###.### 2000-05-03 ====================================================================== Peter's suggestion would certainly fix the problem, but it would introduce a flash that most of the time is unnecessary. To avoid the flash we need to move some of the double painting in JComponent to the heavyweights. ###@###.### 2001-10-22 I'm going to close this as a duplicate of 4155103, as if this is implemented it will fix this case as well. ###@###.### 2001-10-22 4155103 does not fix this issue. I exchanged email with the AWT guys and they indicated overriding getInsets like this is not supported. Ideally getInsets would have been final for Window, but it's too late now. Closing out as will not fix. ###@###.### 2005-03-16 16:57:21 GMT
16-03-2005

WORK AROUND
11-06-2004

PUBLIC COMMENTS
10-06-2004

SUGGESTED FIX Name: pzR10082 Date: 05/03/2000 ------- JFrame.java ------- *** /tmp/domaOVt Wed May 3 14:37:41 2000 --- JFrame.java Wed May 3 14:30:23 2000 *************** *** 325,333 **** * * @param g the Graphics context in which to paint */ ! public void update(Graphics g) { ! paint(g); ! } /** * Sets the menubar for this frame. --- 325,333 ---- * * @param g the Graphics context in which to paint */ ! // public void update(Graphics g) { ! // paint(g); ! // } /** * Sets the menubar for this frame. ###@###.### 2000-05-03 ======================================================================
03-05-2000