This question discusses a known bug where JFrames extend into the windows taskbar. An answer links to the bug report (which has various duplicates) and provides a workaround. I’ve discovered that the problem also holds for JDialogs. The JFrame workaround does not apply. Is there a similar workaround to make JDialogs behave themselves on windows?
Example code:
import javax.swing.*;
public class Demo extends JDialog {
public Demo() {
setSize(250,12500);
setVisible(true);
}
public static void main(String[] args) {
new Demo();
}
}
Edit:
It looks like this will not be fixed in the JDK. This bug report closes with the comment that “If a developer wants to keep their windows entirely visible on the screen, they should consider checking the screen insets themselves [like the solution below], and re-layout their component in a different way, or re-size the window manually after calling pack(), or use a screen-insets-aware layout manager [unlike more common ones like BorderLayout and GridBagLayout].”
This will basically make sure that the dialog “fits” into the specified screen by moving it to be within the bounds of the specified device and shrinking it so that it’s left and bottom edges are within the bounds of the specified device.
This looks at the devices bounds and insets to calculate the “safe” area that the dialog can reside.