首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打开窗口时是否可以使用java.util.Properties-文件来设置窗口的大小?

打开窗口时是否可以使用java.util.Properties-文件来设置窗口的大小?
EN

Stack Overflow用户
提问于 2014-02-13 20:57:26
回答 1查看 106关注 0票数 0

如何使用我的应用程序中的java.util.Properties-文件来记住上次的状态。我希望我的应用程序是在与上次closed.This相同的位置和大小打开的,这是我的代码的一部分:

代码语言:javascript
复制
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();
        }
    });
}}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-13 21:02:55

是的,只需调用setProperty方法即可。然后,在你关闭之前,打电话给保存

启动时,以您已经使用的方式调用加载

甚至比所有这些更好的是,使用首选项

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21765337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档