JDK-4192869 : setBorder(null) requires updateUI() call to reset L&F border
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0,1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 1998-11-25
  • Updated: 2000-02-24
  • Resolved: 2000-02-24
Related Reports
Relates :  
Description

Name: diC59631			Date: 11/25/98


I'm not sure if this is meant to act this way or if there is a bug of a missing property change listener....

If I have a JComponent, like a JButton, where I call setBorder(newBorder), then call setBorder(null) to clear it out, this then has a null/empty Border. However, if I then call updateUI(), this then resets the border to the L&F border for the component. 

Is this correct?
(Review ID: 43219)
======================================================================

Name: krT82822			Date: 10/13/99


10/13/99 eval1127@eng -- filed against 1.2.2, but still present as of 1.3 RA (build "I" of 1.3.0).

JComponents with null borders receive borders after their UI is updated

The bug is as follows: JComponents with null borders receive
borders after their UI is updated. I suspect that whatever's
causing this bug is also causing Bug #ID 4264798

Below is source code which demonstrates the bug. Run the program
and then press the "Click to cause bug" button. Pressing this
button causes the look and feel to be updated on the JTextField.
The bug which occurs is that the JTextField's border which prior
to clicking the "Click to cause bug" button" was null, obtains a
border.

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

public class A extends JFrame
{   
   public A()
   {
      super();
      
      final JPanel p = new JPanel();
      
      setContentPane(p);
      
      p.setBackground(Color.red);
      
      final JButton btn = new JButton("Click to cause bug");
      
      p.add(btn);
      
      final JTextField tf = new JTextField(50);

      tf.setBorder(null);
      
      tf.setText("My border= " + tf.getBorder());
      
      p.add(tf);
            
      btn.addActionListener(new ActionListener()
      {
         public void actionPerformed(ActionEvent ev)
         {
            SwingUtilities.updateComponentTreeUI(tf);
            
            tf.setText("My border= " + tf.getBorder());
            
            btn.setEnabled(false);
         }
      });
   }
   
   public static void main(String args[] )
   {

      A a = new A();
      
      a.pack();

      a.setVisible(true);
   }
}
(Review ID: 96410)
======================================================================

Comments
WORK AROUND Name: diC59631 Date: 11/25/98 Try program with and without updateUI line. import javax.swing.*; import javax.swing.border.*; import java.awt.*; public class AButton { public static void main(String args[]) { JFrame frame = new ExitableJFrame("Sample Borders"); Border border = BorderFactory.createTitledBorder("Pizza Toppings"); JButton button = new JButton ("Help"); button.setBorder(null); // button.updateUI(); Container contentPane = frame.getContentPane(); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); } } ====================================================================== Name: krT82822 Date: 10/13/99 Reset the border after the UI update (Review ID: 96410) ====================================================================== The other solution would be to have the client to a setBorder(EmptyBorder(0,0,0,0)) - the UI would recognize this as a client-installed border and would then not install it's own.
11-06-2004

EVALUATION Name: apC97674 Date: 12/20/99 I believe it would be better if setBorder(null) set the EmptyBorder(0,0,0,0) ###@###.### ====================================================================== Actually, I do not believe this is a bug - it is by design that the UI set a border on a component unless the client sets a non-null border which does not implement the UIResource interface. Rather than setting the border to an EmptyBorder when null is passed in, I'd would advise the client to set an EmptyBorder themselves (a very easy workaround). That way there is no confusion about who's doing what in the code. We might want to beef up the documentation to better explain how this all works. I believe I described this in my Swing Connection "Borders" article (2 years ago), but I can't find it on the current Swing Connection web site! amy.fowler@Eng 2000-02-23
23-02-2000