????注入 ????? IEclipsePreferences ?????如果您正在使用Eclipse插件,请在退出应用程序处理程序中保存eclipse首选项中的边界。 ??
IEclipsePreferences
@Inject @Preference private IEclipsePreferences preferences;
????如果您的应用程序是独立的SWT应用程序,那么您可以使用文件(例如)或数据库来保持shell的边界 ??
mainShell.getBounds() // serialize it in String preferences.put("SHELL_BOUNDS", boundStr);
????在应用程序启动时再次注入首选项并从首选项中检索边界 ??
bounds = preferences.get("SHELL_BOUNDS", "");
????然后你可以设置shell的位置和大小 ??
mainShell.setLocation(xAxis, yAxis); mainShell.setSize(width, height);
????假设这是一个普通的SWT应用程序,你可以使用 ????? SWT.Move ?????每次shell移动时都会听到监听器: ??
SWT.Move
shell.addListener(SWT.Move, event -> { Point location = shell.getLocation(); .... });
????或者你可以使用 ????? SWT.Close ?????监听器只是监听shell关闭: ??
SWT.Close
shell.addListener(SWT.Close, event -> { Point location = shell.getLocation(); .... });
????如果要在应用程序的运行之间保存位置,则必须将位置保存为类似的位置 ????? Properties ?????文件。 ??
Properties