int preferredHeight = 0;
Frame frame = (Frame)getComponent();
// Include title bar width plus left/right title bar borders
Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
preferredWidth = Math.max(preferredWidth, titleBarSize.width + 2);
// Include title bar height plus top/bottom title bar borders
preferredHeight += titleBarSize.height + 2;
// Include menu bar size
MenuBar menuBar = frame.getMenuBar();
if (menuBar != null) {
Dimensions preferredMenuBarSize = menuBar.getPreferredSize();
preferredWidth = Math.max(preferredWidth, preferredMenuBarSize.width);
preferredHeight += preferredMenuBarSize.height;
}
Component content = frame.getContent();
if (content != null) {
Dimensions preferredContentSize = content.getPreferredSize();
preferredWidth = Math.max(preferredWidth, preferredContentSize.width);
preferredHeight += preferredContentSize.height;
}
// Add padding, borders, and content bevel
preferredWidth += (padding.left + padding.right) + 2;
preferredHeight += (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
return new Dimensions(preferredWidth, preferredHeight);
}