private void adjustToImageSize() { if (!isDisplayable()) addNotify(); // Do this to get valid Insets. Insets insets = getInsets(); int imageWidth = mBufferedImage.getWidth(); int imageHeight = mBufferedImage.getHeight(); imageWidth = 600; imageHeight = 550; int w = imageWidth + insets.left + insets.right; int h = imageHeight + insets.top + insets.bottom; h += mControlPanel.getPreferredSize().height; setSize(w, h); }