Non-Resizable Window Borders and Positioning
In situations where non-resizable JFrames are used and Windows Aero is enabled, the setLocation method's behavior may appear inconsistent when considering window borders.
To illustrate this behavior, consider the following code snippet:
import java.awt.Rectangle; import javax.swing.JFrame; public class FrameBorders { public static void main(String[] args) { JFrame frame1 = new JFrame("frame 1"); JFrame frame2 = new JFrame("frame 2"); frame1.setResizable(false); frame2.setResizable(false); frame1.setVisible(true); Rectangle bounds = frame1.getBounds(); frame2.setLocation(bounds.x + bounds.width, bounds.y); frame2.setVisible(true); } }
With this code, you might expect frame2 to be positioned to the right of frame1. However, when Windows Aero is enabled, the borders of the two frames overlap.
Explanation and Solution
Windows Aero applies different styling to non-resizable windows, resulting in a thicker border. Because the setLocation method considers the window's raw dimensions without accounting for the border thickness, it incorrectly positions the windows, leading to the overlapping issue.
To achieve the desired behavior of two non-resizable frames positioned side by side without overlapping borders, you can:
The above is the detailed content of Why Do Non-Resizable JFrames Overlap When Using Windows Aero?. For more information, please follow other related articles on the PHP Chinese website!