我一直在使用Swing应用程序框架,并且对其会话状态存储非常满意。
我想知道是否可以删除(清理)持久状态。
所有对话框形式。
要么
特定对话框形式。
如果不是这样,是否有人找到一种干净的方法来实现此目的(根据操作系统的不同,存储的文件不会保存在同一位置。)
谢谢
最佳答案
您可以通过LocalStorage删除相应的文件(忘记命名的确切详细信息),这是我使用的代码段(与bsaf一起使用,但变化不大,很不公平)
/**
* Deletes the session state by deleting the file. Useful during development
* when restoring to old state is not always the desired behaviour.
* Pending: this is incomplete, deletes the mainframe state only.
*/
protected void deleteSessionState() {
ApplicationContext context = getContext();
try {
context.getLocalStorage().deleteFile("mainFrame.session.xml");
} catch (...) {
}
}