Swing/MagneticFrame のバックアップ差分(No.11)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/MagneticFrame へ行く。
- 1 (2007-01-01 (月) 08:38:12)
- 2 (2007-01-01 (月) 10:20:49)
- 3 (2007-01-02 (火) 18:05:01)
- 4 (2007-01-02 (火) 21:18:58)
- 5 (2007-01-02 (火) 23:36:18)
- 6 (2007-08-31 (金) 13:10:20)
- 7 (2009-06-22 (月) 12:27:29)
- 8 (2013-02-10 (日) 00:03:14)
- 9 (2013-10-16 (水) 14:15:27)
- 10 (2013-10-17 (木) 04:21:50)
- 11 (2015-02-10 (火) 15:30:35)
- 12 (2016-12-08 (木) 14:26:39)
- 13 (2017-11-15 (水) 21:10:41)
- 14 (2019-05-22 (水) 19:35:38)
- 15 (2019-07-17 (水) 14:50:36)
- 16 (2021-03-21 (日) 04:15:18)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JDesktopPaneにJInternalFrameを吸着させる #navi(../) #tags(DesktopManager, JDesktopPane, JInternalFrame) RIGHT:Posted by &author(aterai); at 2007-01-01 * JDesktopPaneにJInternalFrameを吸着させる [#t9488112] --- title: JDesktopPaneにJInternalFrameを吸着させる tags: [DesktopManager, JDesktopPane, JInternalFrame] author: aterai pubdate: 2007-01-01T08:38:12+09:00 description: JDesktopPaneとJInternalFrameの距離が近くなった場合、これらを自動的に吸着させます。 --- * 概要 [#t9488112] `JDesktopPane`と`JInternalFrame`の距離が近くなった場合、これらを自動的に吸着させます。 - &jnlp; - &jar; - &zip; #download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTPnXoiDZI/AAAAAAAAAeQ/9SMGwoIqOi8/s800/MagneticFrame.png) #ref(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTPnXoiDZI/AAAAAAAAAeQ/9SMGwoIqOi8/s800/MagneticFrame.png) ** サンプルコード [#o8501b2d] * サンプルコード [#o8501b2d] #code(link){{ desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); desktop.setDesktopManager(new DefaultDesktopManager() { @override public void dragFrame(JComponent frame, int x, int y) { @Override public void dragFrame(JComponent frame, int x, int y) { int e = x; int n = y; int w = desktop.getSize().width -frame.getSize().width -e; int s = desktop.getSize().height-frame.getSize().height-n; if(isNear(e) || isNear(n) || isNear(w) || isNear(s)) { x = (e<w)?(isNear(e)?0:e):(isNear(w)?w+e:e); y = (n<s)?(isNear(n)?0:n):(isNear(s)?s+n:n); } super.dragFrame(frame, x, y); } private boolean isNear(int c) { return (Math.abs(c)<10); } }); }} ** 解説 [#oa45d781] * 解説 [#oa45d781] `DesktopManager#dragFrame(JInternalFrame,int,int)`メソッドをオーバーライドすることで`JInternalFrame`の位置を調整しています。上記のサンプルでは、`JDesktopPane`と`JInternalFrame`の距離が`10px`以下になった場合、それぞれ吸着するよう設定しています。 //**参考リンク ** コメント [#y9744126] //* 参考リンク * コメント [#y9744126] #comment #comment