Dimension () { Dimension custom = getWindowPreferredSize(); Dimension superSize = super.getPreferredSize(); if (custom != null) { custom.width = custom.width > 0 ? custom.width : superSize.width; custom.height = custom.height > 0 ? custom.height : superSize.height; } else { custom = superSize; } return custom; }