Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我无法在swing项目中保存表更改_Java_Swing_Properties_Preference_Savechanges - Fatal编程技术网

Java 我无法在swing项目中保存表更改

Java 我无法在swing项目中保存表更改,java,swing,properties,preference,savechanges,Java,Swing,Properties,Preference,Savechanges,我更改表的行位置并保存它。但当我再次关闭并打开项目时,它会按照自己的意愿设计表格。关于保存swing项目更改有什么想法吗?有什么技术、方法吗?这是我的保存方法 公共void saveLayoutData(字符串预路径){ 可能还需要用于加载preferences/XML的代码,因为它可能很容易在那里停滞。您是否尝试将要保存的数据写入console以确保它被保存?光盘上的XML文件是否正在填充?我有loadLayoutData方法。当我更改表的行位置并保存它时,我想程序会随机创建它。我怎样才能防止

我更改表的行位置并保存它。但当我再次关闭并打开项目时,它会按照自己的意愿设计表格。关于保存swing项目更改有什么想法吗?有什么技术、方法吗?这是我的保存方法

公共void saveLayoutData(字符串预路径){


可能还需要用于加载preferences/XML的代码,因为它可能很容易在那里停滞。您是否尝试将要保存的数据写入console以确保它被保存?光盘上的XML文件是否正在填充?我有loadLayoutData方法。当我更改表的行位置并保存它时,我想程序会随机创建它。我怎样才能防止这种情况发生。如何将真实的行填充到表中。谢谢
    Properties pMain = new Properties();
    File dirMain = new File(prePath + "DWorkSpacesAll" + ".xml");
    File dirPath = new File(prePath);
    if (!dirPath.exists()) {
        File dirBase = new File("./Preferences");
        dirBase.mkdir();
        dirPath.mkdir();
    }
    if (!dirMain.exists()) {
        try {
            dirMain.createNewFile();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    pMain.put("ShowConfirmationDialog", showConfirmation.toString());
    for (DWorkspace w : workSpaces) {
        try {
            w.setTitle(tabbedPane.getTitleAt(workSpaces.indexOf(w)));
        } catch (Exception e) {
            continue;
        }

        pMain.put(w.getPreferenceKey(), w.getTitle());
        File dir = new File(prePath + w.getPreferenceKey() + ".dat");


        try {
            if (!dirPath.exists()) {
                File dirBase = new File("./Preferences");
                dirBase.mkdir();
                dirPath.mkdir();
            }
            if (!dir.exists()) {
                dir.createNewFile();
            }
            w.getDockingManager().
                    saveLayoutDataToFile(dir.getCanonicalPath());
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    FileOutputStream fosMain = null;
    try {
        fosMain = new FileOutputStream(dirMain.getCanonicalPath());
        pMain.storeToXML(fosMain, "");
        fosMain.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (fosMain != null) {
                fosMain.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    try {

        for (DWorkspace w : workSpaces) {
            File dir = new File(prePath + w.getPreferenceKey() + ".xml");

            Properties p = new Properties();

            for (DIComponent c : w.getComponents()) {

                if (c instanceof DIWithPreferences) {

                    DIWithPreferences cwp = (DIWithPreferences) c;

                    String pref = cwp.getPreferences();

                    if (pref != null) {
                        p.put("_" + w.getPreferenceKey() + "_" + cwp.getKey(), pref);
                    }

                }
            }

            p.put("_" + w.getPreferenceKey() + "_" + "Table1", w.Table1());

            p.put("_" + w.getPreferenceKey() + "_" + "Table2",
                    w.Table2());

            p.put("_" + w.getPreferenceKey() + "_" + "Table3",
                    w.Table3());

            p.put("_" + w.getPreferenceKey() + "_" + "Table4",
                    w.Table4());

            if (w.getPreferenceKey() == null) {
            } else {
                p.put("_" + w.getPreferenceKey() + "_" + "Table5",
                        w.Table5());
            }

            if (w.getPreferenceKey() == null) {
            } else {
                p.put("_" + w.getPreferenceKey() + "_" + "Table6",
                        w.Table6());
            }

            FileOutputStream fos = new FileOutputStream(dir.getCanonicalPath());
            p.storeToXML(fos, "");
            fos.close();

        }
    } catch (Exception ex) {
        log.error("", ex);
    }
}