Skip to main content

Java7b121 Bug, TitledBorder insets vary

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
wzberger
Offline
Joined: 2004-08-31

In Java7b121 the insets of a titled border will be modified. Execute the test case below and resize the window.

 

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;
    }   
  }

Thanks,

Wolfgang

www.jyloo.com

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
robilad
Offline
Joined: 2004-05-05

If the issue persists with the latest build, please report a bug at http://bugreport.sun.com/bugreport/ .
Dalibor Topic, Java F/OSS Ambassador, Java Products Group, Oracle