JDK-7034614 : The insets of TitledBorder vary, will be modified by another method, in JDK7
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-04-07
  • Updated: 2012-03-20
  • Resolved: 2011-05-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b140Fixed
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b136)
Java HotSpot(TM) Client VM (build 21.0-b06, mixed mode, sharing)


A DESCRIPTION OF THE PROBLEM :
The insets of a TitledBorder will be modified by another method.


REGRESSION.  Last worked in version 6u24

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the test case below and resize the window.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The insets should stay unchanged.

ACTUAL -
The insets vary.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

public class TitledBorderInsetsTest extends JFrame
{
  public static void main(String[] args)
  {
    EventQueue.invokeLater(new Runnable(){
      public void run()
      {
        try
        {
          UIManager.put("TitledBorder.border", new MyTitledBorder());
          new TitledBorderInsetsTest();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }

  public TitledBorderInsetsTest() throws Exception
  {
    JPanel p = new JPanel();
    p.setBorder(new TitledBorder("Foo"));
    p.add(new JLabel("Label"));
    add(p);
    
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(new Dimension(600, 300));
    setLocationRelativeTo(null);
    setVisible(true);
  }
  
  public static class MyTitledBorder implements Border
  {
    private Insets insets = new Insets(20,20,20,20);
    
    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
    {
      System.err.println(insets);
    }

    @Override
    public Insets getBorderInsets(Component c)
    {
      return insets;
    }

    @Override
    public boolean isBorderOpaque()
    {
      return false;
    }
  }
}  

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

Comments
EVALUATION It is a bad idea to return shared insets which could be changed by anyone. But JDK libraries should not change them.
14-04-2011