如何防止JFrame元素从其位置移位? [关闭]

问题描述 投票:0回答:1
我在Netbeans中使用JFrame创建了一个登录表单。当我运行程序并最大化窗口时,框架的元素会移位,并且不会根据新屏幕调整大小]

https://imgur.com/a/WPYU6Sv

java swing jframe layout-manager
1个回答
-1
投票
每个

J-component具有setBounds功能,与parent frame左上角相比,它使您可以固定组件。

/** * Moves and resizes this component. The new location of the top-left * corner is specified by <code>x</code> and <code>y</code>, and the * new size is specified by <code>width</code> and <code>height</code>. * <p> * This method changes layout-related information, and therefore, * invalidates the component hierarchy. * * @param x the new <i>x</i>-coordinate of this component * @param y the new <i>y</i>-coordinate of this component * @param width the new <code>width</code> of this component * @param height the new <code>height</code> of this * component * @see #getBounds * @see #setLocation(int, int) * @see #setLocation(Point) * @see #setSize(int, int) * @see #setSize(Dimension) * @see #invalidate * @since JDK1.1 */ public void setBounds(int x, int y, int width, int height) { reshape(x, y, width, height); }
我希望这会有所帮助。
© www.soinside.com 2019 - 2024. All rights reserved.