@Override
public int getPreferredWidth(int height) {
int preferredWidth = 0;
Border border = (Border)getComponent();
int topThickness = thickness;
String title = border.getTitle();
if (title != null
&& title.length() > 0) {
Rectangle2D headingBounds = font.getStringBounds(title, fontRenderContext);
preferredWidth = (int)Math.ceil(headingBounds.getWidth());
LineMetrics lm = font.getLineMetrics(title, fontRenderContext);
topThickness = Math.max((int)Math.ceil(lm.getHeight()), topThickness);
}
Component content = border.getContent();
if (content != null) {
if (height != -1) {
height = Math.max(height - (topThickness + thickness) -
padding.top - padding.bottom, 0);
}