Swing/DragWindow のバックアップソース(No.9)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/DragWindow へ行く。
- 1 (2006-09-12 (火) 17:24:39)
- 2 (2007-08-10 (金) 12:33:24)
- 3 (2008-01-23 (水) 20:14:53)
- 4 (2008-02-22 (金) 13:04:00)
- 5 (2008-03-25 (火) 17:53:48)
- 6 (2010-01-18 (月) 11:35:44)
- 7 (2010-10-06 (水) 12:36:32)
- 8 (2012-08-14 (火) 15:55:31)
- 9 (2013-03-14 (木) 08:00:42)
- 10 (2013-03-14 (木) 13:53:25)
- 11 (2013-03-15 (金) 11:08:52)
- 12 (2013-03-15 (金) 12:30:42)
- 13 (2013-03-15 (金) 13:56:42)
- 14 (2013-03-15 (金) 22:34:12)
- 15 (2013-03-18 (月) 15:34:53)
- 16 (2013-03-19 (火) 04:21:51)
- 17 (2013-03-19 (火) 16:03:51)
- 18 (2013-03-20 (水) 06:49:58)
- 19 (2013-04-12 (金) 01:25:06)
- 20 (2014-02-10 (月) 18:58:39)
- 21 (2015-02-10 (火) 15:25:33)
- 22 (2015-03-28 (土) 15:36:18)
- 23 (2016-05-26 (木) 14:48:43)
- 24 (2016-09-02 (金) 13:30:48)
- 25 (2017-04-04 (火) 14:17:08)
- 26 (2017-10-14 (土) 17:53:09)
- 27 (2018-08-19 (日) 17:44:54)
- 28 (2018-11-07 (水) 19:10:45)
- 29 (2020-11-04 (水) 16:05:25)
- 30 (2022-10-14 (金) 13:43:24)
- 31 (2024-02-03 (土) 14:10:31)
TITLE:JWindowをマウスで移動 #navi(../) #tags() RIGHT:Posted by &author(aterai); at 2004-09-06 *JWindowをマウスで移動 [#g9940ceb] JWindowなどのタイトルバーのないフレームをマウスで移動します。 -&jnlp; -&jar; -&zip; //#screenshot #ref(http://lh6.ggpht.com/_9Z4BYR88imo/TQTL8cG8F0I/AAAAAAAAAYY/vZfyqnyr6-I/s800/DragWindow.png) **サンプルコード [#r3a65b7b] #code(link){{ public void createSplashScreen(String path) { ImageIcon img = new ImageIcon(getClass().getResource(path)); DragWindowListener dwl = new DragWindowListener(); splashLabel = new JLabel(img); splashLabel.addMouseListener(dwl); splashLabel.addMouseMotionListener(dwl); splashScreen = new JWindow(getFrame()); splashScreen.getContentPane().add(splashLabel); splashScreen.pack(); splashScreen.setLocationRelativeTo(null); } class DragWindowListener extends MouseAdapter { private MouseEvent start; //private Point loc; private Window window; @Override public void mousePressed(MouseEvent me) { start = me; } @Override public void mouseDragged(MouseEvent me) { if(window==null) { window = SwingUtilities.windowForComponent(me.getComponent()); } Point eventLocationOnScreen = me.getLocationOnScreen(); window.setLocation(eventLocationOnScreen.x - start.getX(), eventLocationOnScreen.y - start.getY()); //loc = window.getLocation(loc); //int x = loc.x - start.getX() + me.getX(); //int y = loc.y - start.getY() + me.getY(); //window.setLocation(x, y); } } }} **解説 [#p1806440] JWindowや、setUndecorated(true)したJFrameのようにタイトルバーのないフレームをマウスのドラッグで移動します。実際はJWindowに、MouseMotionListenerなどを実装したコンポーネントを追加しています。 上記のサンプルでは、Splash ScreenのJLabelにリスナーを追加し、これをJWindowに貼り付けてドラッグできるようにしています。 次に開くsetUndecorated(true)したJFrameでは、青いラベル部分をドラッグすることが出来ます。 ---- - マルチディスプレイなどで、別画面に移動できないバグ?を修正。 -- ただし、Web Start のSandBox内では、以前と同じく画面の外に移動することができない? --- JNLP のセキュリティに all-permissions を設定する必要がある - Swing Tutorial の [http://docs.oracle.com/javase/tutorial/uiswing/examples/components/index.html#FrameDemo2 FrameDemo2]で試しても、同様? -- "Look and feel decorated": 画面外に移動不可 -- "Window system decorated": 画面外に移動可能 **参考リンク [#n4c8a267] -[[JInternalFrameをJFrameとして表示する>Swing/InternalFrameTitleBar]] -[[JFrameのタイトルバーなどの装飾を独自のものにカスタマイズする>Swing/CustomDecoratedFrame]] **コメント [#hfe1ff82] #comment