是否可以使用java.util.Properties-files设置窗口打开时的大小?
如何在应用程序中使用java.util.Properties-files来记住上次的状态。我希望我的应用程序在上次关闭时的相同位置和大小打开。这是我代码的一部分:是否可以使用java.util.Properties-files设置窗口打开时的大小?,java,user-interface,Java,User Interface,如何在应用程序中使用java.util.Properties-files来记住上次的状态。我希望我的应用程序在上次关闭时的相同位置和大小打开。这是我代码的一部分: private static void createAndShowGUI() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("Infinity"); v demo = new v(); frame.s
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Infinity");
v demo = new v();
frame.setContentPane(demo.createContentPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setSize(new Dimension(740, 480));
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Properties prop = new Properties();
// add some properties
prop.setProperty("Height", "200");
prop.put("Width", "1500");
// print the list
try {
// store the properties list in an output stream
prop.store(System.out, "PropertiesDemo");
} catch (IOException ex) {
ex.printStackTrace();
}
createAndShowGUI();
}
});
}}
是的,只需调用该方法。然后,就在你关门之前,打电话给我
当你开始时,用你现在的方式打电话
甚至比所有这些都好,使用 @user3061922 1)您没有调用
load
。您只是“存储”在控制台上。你需要把它归档。你知道什么是更好的解决办法吗?上课,你说的负荷是什么意思?我必须在文件中创建包含属性的txt文件,然后加载它?@user3061922如果您使用首选项
,则不能加载。使用首选项
。是的,我上传了我的代码