设置窗口下次可见时应该出现的位置:本机窗口系统的默认位置,还是当前位置(由 getlocation 返回)。此行为模拟显示的本机窗口,而不是以编程方式设置其位置。如果未显式设置窗口的位置,那么大多数窗口操作系统将重叠显示窗口。一旦窗口显示在屏幕上,其实际位置就被确定。
还可以通过将系统属性 "java.awt.window.locationbyplatform" 设置为 "true" 来启用此行为,但应优先考虑调用此方法。
在调用 setlocationbyplatform 清除窗口的此属性之后,调用 setvisible、setlocation 和 setbounds。
例如,在执行以下代码后:
setlocationbyplatform(true);
setvisible(true);
boolean flag = islocationbyplatform();
窗口将显示在平台的默认位置,flag 将为 false。
在以下示例中:
setlocationbyplatform(true);
setlocation(10, 10);
boolean flag = islocationbyplatform();
setvisible(true);
窗口将显示在 (10, 10) 的位置,flag 将为 false。
- 参数:
locationbyplatform - 如果此窗口应出现在默认位置,则为 true,如果应出现在当前位置,则为 false
- 抛出:
illegalcomponentstateexception - 如果此窗口显示在屏幕上,且 locationbyplatform 为 true。- 从以下版本开始:
- 1.5
- 另请参见:
component.setlocation(int, int),
isshowing(),
setvisible(boolean),
islocationbyplatform(),
system.getproperty(string)