Instead of manually calculating window and frame dimensions, call the pack() method when you can. This will lay-out components and calculate the optimal size of the Frame (can also be applied to dialogs).
See also Frame Background Image Packing workaround.