diff --git a/src/share/classes/javax/swing/border/TitledBorder.java b/src/share/classes/javax/swing/border/TitledBorder.java index 3bf385e44c11958fabaeb385a6eab0133892bdc4..929fbd07f5be821a27f6cc2089946aa22111fcab 100644 --- a/src/share/classes/javax/swing/border/TitledBorder.java +++ b/src/share/classes/javax/swing/border/TitledBorder.java @@ -165,11 +165,11 @@ public class TitledBorder extends AbstractBorder * @param titlePosition the position for the title */ public TitledBorder(Border border, - String title, - int titleJustification, - int titlePosition) { + String title, + int titleJustification, + int titlePosition) { this(border, title, titleJustification, - titlePosition, null, null); + titlePosition, null, null); } /** @@ -183,12 +183,12 @@ public class TitledBorder extends AbstractBorder * @param titleFont the font for rendering the title */ public TitledBorder(Border border, - String title, - int titleJustification, - int titlePosition, - Font titleFont) { + String title, + int titleJustification, + int titlePosition, + Font titleFont) { this(border, title, titleJustification, - titlePosition, titleFont, null); + titlePosition, titleFont, null); } /** @@ -205,11 +205,11 @@ public class TitledBorder extends AbstractBorder */ @ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"}) public TitledBorder(Border border, - String title, - int titleJustification, - int titlePosition, - Font titleFont, - Color titleColor) { + String title, + int titleJustification, + int titlePosition, + Font titleFont, + Color titleColor) { this.title = title; this.border = border; this.titleFont = titleFont; @@ -234,7 +234,7 @@ public class TitledBorder extends AbstractBorder * @param height the height of the painted border */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { - Border border = getBorderUI(); + Border border = getBorder(); String title = getTitle(); if ((title != null) && !title.isEmpty()) { int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; @@ -347,7 +347,7 @@ public class TitledBorder extends AbstractBorder * @param insets the object to be reinitialized */ public Insets getBorderInsets(Component c, Insets insets) { - Border border = getBorderUI(); + Border border = getBorder(); if (border == null) { insets.set(0, 0, 0, 0); } @@ -402,22 +402,34 @@ public class TitledBorder extends AbstractBorder /** * Returns whether or not the border is opaque. */ - public boolean isBorderOpaque() { return false; } + public boolean isBorderOpaque() { + return false; + } /** * Returns the title of the titled border. + * + * @return the title of the titled border */ - public String getTitle() { return title; } + public String getTitle() { + return title; + } /** * Returns the border of the titled border. + * + * @return the border of the titled border */ public Border getBorder() { - return border; + return border != null + ? border + : UIManager.getBorder("TitledBorder.border"); } /** * Returns the title-position of the titled border. + * + * @return the title-position of the titled border */ public int getTitlePosition() { return titlePosition; @@ -425,20 +437,28 @@ public class TitledBorder extends AbstractBorder /** * Returns the title-justification of the titled border. + * + * @return the title-justification of the titled border */ - public int getTitleJustification() { return titleJustification; } + public int getTitleJustification() { + return titleJustification; + } /** * Returns the title-font of the titled border. + * + * @return the title-font of the titled border */ - public Font getTitleFont() { + public Font getTitleFont() { return titleFont; } /** * Returns the title-color of the titled border. + * + * @return the title-color of the titled border */ - public Color getTitleColor() { + public Color getTitleColor() { return titleColor; } @@ -447,15 +467,19 @@ public class TitledBorder extends AbstractBorder /** * Sets the title of the titled border. - * param title the title for the border + * @param title the title for the border */ - public void setTitle(String title) { this.title = title; } + public void setTitle(String title) { + this.title = title; + } /** * Sets the border of the titled border. * @param border the border */ - public void setBorder(Border border) { this.border = border; } + public void setBorder(Border border) { + this.border = border; + } /** * Sets the title-position of the titled border. @@ -482,19 +506,19 @@ public class TitledBorder extends AbstractBorder * Sets the title-justification of the titled border. * @param titleJustification the justification for the border */ - public void setTitleJustification(int titleJustification) { + public void setTitleJustification(int titleJustification) { switch (titleJustification) { - case DEFAULT_JUSTIFICATION: - case LEFT: - case CENTER: - case RIGHT: - case LEADING: - case TRAILING: - this.titleJustification = titleJustification; - break; - default: - throw new IllegalArgumentException(titleJustification + - " is not a valid title justification."); + case DEFAULT_JUSTIFICATION: + case LEFT: + case CENTER: + case RIGHT: + case LEADING: + case TRAILING: + this.titleJustification = titleJustification; + break; + default: + throw new IllegalArgumentException(titleJustification + + " is not a valid title justification."); } } @@ -518,6 +542,7 @@ public class TitledBorder extends AbstractBorder * Returns the minimum dimensions this border requires * in order to fully display the border and title. * @param c the component where this border will be drawn + * @return the {@code Dimension} object */ public Dimension getMinimumSize(Component c) { Insets insets = getBorderInsets(c); @@ -557,7 +582,7 @@ public class TitledBorder extends AbstractBorder if (height < 0) { throw new IllegalArgumentException("Height must be >= 0"); } - Border border = getBorderUI(); + Border border = getBorder(); String title = getTitle(); if ((title != null) && !title.isEmpty()) { int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; @@ -616,13 +641,6 @@ public class TitledBorder extends AbstractBorder return Component.BaselineResizeBehavior.OTHER; } - private Border getBorderUI() { - Border border = getBorder(); - return border != null - ? border - : UIManager.getBorder("TitledBorder.border"); - } - private int getPosition() { int position = getTitlePosition(); if (position != DEFAULT_POSITION) { diff --git a/test/javax/swing/border/Test6981576.java b/test/javax/swing/border/Test6981576.java new file mode 100644 index 0000000000000000000000000000000000000000..479118f1b9ff61848a6db4392d7bde85b141a84c --- /dev/null +++ b/test/javax/swing/border/Test6981576.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6981576 + * @summary Tests that default border for the titled border is not null + * @author Sergey Malenkov + */ + +import java.awt.Component; +import java.awt.Graphics; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.UIManager.LookAndFeelInfo; +import javax.swing.border.TitledBorder; + +public class Test6981576 extends TitledBorder implements Runnable, Thread.UncaughtExceptionHandler { + public static void main(String[] args) { + SwingUtilities.invokeLater(new Test6981576()); + } + + private int index; + private LookAndFeelInfo[] infos; + private JFrame frame; + + private Test6981576() { + super(""); + } + + @Override + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + getBorder().paintBorder(c, g, x, y, width, height); + } + + public void run() { + if (this.infos == null) { + this.infos = UIManager.getInstalledLookAndFeels(); + Thread.currentThread().setUncaughtExceptionHandler(this); + JPanel panel = new JPanel(); + panel.setBorder(this); + this.frame = new JFrame(getClass().getSimpleName()); + this.frame.add(panel); + this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.frame.setVisible(true); + } + if (this.index == this.infos.length) { + this.frame.dispose(); + } + else { + LookAndFeelInfo info = this.infos[this.index % this.infos.length]; + try { + UIManager.setLookAndFeel(info.getClassName()); + } + catch (Exception exception) { + System.err.println("could not change look and feel"); + } + SwingUtilities.updateComponentTreeUI(this.frame); + this.frame.pack(); + this.frame.setLocationRelativeTo(null); + this.index++; + SwingUtilities.invokeLater(this); + } + } + + public void uncaughtException(Thread thread, Throwable throwable) { + System.exit(1); + } +}