Swing/Preferences のバックアップ(No.1)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/Preferences へ行く。
- 1 (2004-05-10 (月) 12:45:22)
- 2 (2004-06-02 (水) 09:58:32)
- 3 (2004-08-04 (水) 03:07:23)
- 4 (2004-10-08 (金) 06:24:19)
- 5 (2004-11-04 (木) 10:10:03)
- 6 (2005-02-03 (木) 02:04:18)
- 7 (2005-04-28 (木) 04:32:37)
- 8 (2005-06-29 (水) 22:03:11)
- 9 (2005-11-03 (木) 16:30:33)
- 10 (2006-02-27 (月) 16:18:57)
- 11 (2006-05-30 (火) 11:29:26)
- 12 (2007-05-10 (木) 10:48:30)
- 13 (2007-06-14 (木) 14:42:00)
- 14 (2007-10-26 (金) 12:20:16)
- 15 (2007-10-26 (金) 13:37:15)
- 16 (2008-04-24 (木) 19:54:41)
- 17 (2011-05-04 (水) 18:57:53)
- 18 (2012-03-26 (月) 15:46:11)
- 19 (2013-02-26 (火) 14:53:13)
- 20 (2013-05-03 (金) 23:46:28)
- 21 (2014-12-25 (木) 16:08:29)
- 22 (2015-03-02 (月) 11:17:32)
- 23 (2015-06-23 (火) 16:15:40)
- 24 (2016-06-01 (水) 18:43:35)
- 25 (2017-04-04 (火) 14:13:45)
- 26 (2017-09-08 (金) 19:16:43)
- 27 (2018-02-27 (火) 14:34:35)
- 28 (2020-03-06 (金) 16:27:52)
- 29 (2021-08-20 (金) 13:59:29)
#navi(contents-page-name): No such page: ST
FrontPage>Swing Tips?>ST/Preferences?
ST/Preferences?
Terai Atsuhiro 2021-08-20 (金) 13:59:29
public abstract class AbstractHogePanel extends JPanel{ final private Point pos = new Point(0, 0); final private Dimension dim = new Dimension(900, 800); private JFrame frame; public AbstractHogePanel(){ super(); frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); frame.addWindowListener(new java.awt.event.WindowAdapter(){ public void windowClosing(WindowEvent e){ exitActionPerformed(null); } }); frame.addComponentListener(new ComponentAdapter(){ public void componentMoved(ComponentEvent e){ JFrame frm = (JFrame)e.getSource(); if(frm.getExtendedState()==JFrame.NORMAL){ try{ pos.setLocation(frm.getLocationOnScreen()); }catch(IllegalComponentStateException icse){} } } public void componentResized(ComponentEvent e){ JFrame frm = (JFrame)e.getSource(); if(frm.getExtendedState()==JFrame.NORMAL){ dim.setSize(getSize()); } } //void componentHidden(ComponentEvent e){} //void componentShown(ComponentEvent e) }); } private String prefix = ""; protected void setPrefix(String str){ str = str.toLowerCase().trim(); if(str!=null && str.length()>0){ prefix = str+"_"; } } protected void initLocation(Preferences lprefs){ int xpos = lprefs.getInt(prefix+"locx", pos.x); int ypos = lprefs.getInt(prefix+"locy", pos.y); pos.setLocation(xpos,ypos); getFrame().setLocation(pos.x, pos.y); int wdim = lprefs.getInt(prefix+"dimw", dim.width); int hdim = lprefs.getInt(prefix+"dimh", dim.height); dim.setSize(wdim, hdim); this.setPreferredSize(dim); } protected void saveLocation(Preferences lprefs){ lprefs.putInt(prefix+"locx", pos.x); lprefs.putInt(prefix+"locy", pos.y); lprefs.putInt(prefix+"dimw", dim.width); lprefs.putInt(prefix+"dimh", dim.height); try{ lprefs.flush(); }catch(java.util.prefs.BackingStoreException e){ } } public JFrame getFrame(){ return frame; } public void showPanel(){ if(getFrame()!=null){ JFrame f = getFrame(); f.setExtendedState(JFrame.NORMAL); f.getContentPane().add(this, BorderLayout.CENTER); f.pack(); f.show(); } } protected class ExitAction extends AbstractAction{ public ExitAction(){ super("exit"); } public void actionPerformed(ActionEvent evt){ exitActionPerformed(evt); } } abstract public void exitActionPerformed(ActionEvent e); }
public void exitActionPerformed(ActionEvent e){ Preferences prefs = Preferences.userNodeForPackage(getClass()); //Preferences prefs = getPreferences(); //prefs.putBoolean("file_flag", xmlCheck.isSelected()); saveLocation(prefs); JFrame frm = getFrame(); frm.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); frm.dispose(); }