Swing/PersistenceService のバックアップ差分(No.1)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/PersistenceService へ行く。
- 1 (2012-03-26 (月) 15:45:39)
- 2 (2012-04-17 (火) 16:56:49)
- 3 (2012-04-17 (火) 19:53:11)
- 4 (2012-06-15 (金) 21:15:15)
- 5 (2012-06-23 (土) 05:08:04)
- 6 (2012-11-16 (金) 18:50:43)
- 7 (2012-12-13 (木) 15:14:56)
- 8 (2012-12-26 (水) 11:30:04)
- 9 (2013-05-03 (金) 23:45:05)
- 10 (2013-05-07 (火) 05:48:15)
- 11 (2013-11-14 (木) 19:06:49)
- 12 (2014-10-08 (水) 18:35:33)
- 13 (2014-10-13 (月) 06:51:47)
- 14 (2014-10-17 (金) 15:04:11)
- 15 (2014-12-20 (土) 13:22:57)
- 16 (2015-02-25 (水) 17:36:09)
- 17 (2015-06-23 (火) 16:15:22)
- 18 (2015-11-26 (木) 04:34:21)
- 19 (2016-05-26 (木) 15:29:02)
- 20 (2016-05-31 (火) 15:12:52)
- 21 (2017-02-20 (月) 18:24:55)
- 22 (2018-01-02 (火) 21:42:35)
- 23 (2019-12-26 (木) 16:53:52)
- 24 (2021-07-02 (金) 17:55:08)
- 25 (2023-03-09 (木) 19:03:41)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:PersistenceServiceを使ってJFrameの位置・サイズを記憶 #navi(../) RIGHT:Posted by [[aterai]] at 2012-03-26 *PersistenceServiceを使ってJFrameの位置・サイズを記憶 [#da09cfeb] ServiceManagerからPersistenceServiceを取得し、JFrameなどの位置・サイズの保存、呼び出しを行います。 -&jnlp; -&jar; -&zip; //#screenshot #ref(https://lh6.googleusercontent.com/-PyOW5DW5kHU/T3APD_Cq_bI/AAAAAAAABKk/i9eivMuQZ0Y/s800/PersistenceService.png) **サンプルコード [#xdef909f] #code{{ final WindowState ws = new WindowState(); SwingWorker<WindowAdapter,Void> worker = new SwingWorker<WindowAdapter,Void>() { @Override public WindowAdapter doInBackground() { PersistenceService ps; BasicService bs; try{ bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService"); ps = (PersistenceService)ServiceManager.lookup("javax.jnlp.PersistenceService"); }catch(UnavailableServiceException use) { use.printStackTrace(); ps = null; bs = null; } if(ps != null && bs != null) { final PersistenceService persistenceService = ps; final URL codebase = bs.getCodeBase(); loadWindowState(persistenceService, codebase, ws); return new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { JFrame f = (JFrame)e.getComponent(); if(f.getExtendedState()==JFrame.NORMAL) { ws.setSize(f.getSize()); ws.setLocation(f.getLocationOnScreen()); } saveWindowState(persistenceService, codebase, ws); } }; }else{ return null; } } @Override public void done() { WindowAdapter wa = null; try{ wa = get(); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e) { e.printStackTrace(); } JFrame frame = new JFrame(); if(wa!=null) frame.addWindowListener(wa); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new MainPanel()); frame.setSize(ws.getSize()); frame.setLocation(ws.getLocation()); frame.setVisible(true); } }; worker.execute(); }} **解説 [#p124cd93] 上記のサンプルでは、PersistenceServiceで確保したファイルに、HashMap<String, Serializable>に格納したJFrameの位置、サイズをXMLEncoder、XMLDecoderを使って読み書きしています。 ---- - Windows 7, JDK 1.7.0_03 では、C:\Users\(user)\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\muffin 以下に mufファイルなどが作成されるようです。 #code{{ <?xml version="1.0" encoding="UTF-8"?> <java version="1.7.0_03" class="java.beans.XMLDecoder"> <object class="java.util.HashMap"> <void method="put"> <string>location</string> <object idref="Point0"/> </void> <void method="put"> <string>size</string> <object idref="Dimension0"/> </void> </object> </java> }} **参考リンク [#m74e8dfc] - [http://pscode.org/jws/api.html JWS javax.jnlp.* API demos] - [http://java.sun.com/javase/ja/6/docs/ja/technotes/guides/javaws/developersguide/examples.html#PersistenceService PersistenceService] - [http://www.finnw.me.uk/persistencetest.html PersistenceService Demo] **コメント [#x92d06e4] #comment