Swing/InternalFrameTitleBar のバックアップソース(No.14)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/InternalFrameTitleBar へ行く。
- 1 (2009-08-31 (月) 15:27:18)
- 2 (2009-08-31 (月) 17:21:54)
- 3 (2009-11-12 (木) 19:53:12)
- 4 (2009-11-13 (金) 14:56:10)
- 5 (2010-01-01 (金) 01:10:51)
- 6 (2010-01-18 (月) 11:35:05)
- 7 (2010-06-10 (木) 15:07:18)
- 8 (2010-08-02 (月) 02:19:26)
- 9 (2010-08-02 (月) 15:19:36)
- 10 (2011-04-21 (木) 16:01:06)
- 11 (2013-01-06 (日) 21:40:38)
- 12 (2013-06-15 (土) 17:45:00)
- 13 (2013-06-17 (月) 02:29:21)
- 14 (2013-07-26 (金) 01:34:07)
- 15 (2014-12-01 (月) 15:12:30)
- 16 (2015-01-28 (水) 15:04:43)
- 17 (2015-04-01 (水) 20:09:38)
- 18 (2015-04-03 (金) 16:07:54)
- 19 (2017-02-24 (金) 19:03:18)
- 20 (2018-01-03 (水) 19:55:34)
- 21 (2018-02-24 (土) 19:51:30)
- 22 (2019-12-25 (水) 19:45:24)
- 23 (2021-06-27 (日) 01:46:45)
TITLE:JInternalFrameをJFrameとして表示する #navi(../) #tags(JFrame, JInternalFrame, MouseListener, MouseMotionListener) RIGHT:Posted by &author(aterai); at 2009-08-31 *JInternalFrameをJFrameとして表示する [#tf5e5ced] ``JFrame``のタイトルバーなどを非表示にし、``JInternalFrame``のタイトルバーでこれらを代用します。 -&jnlp; -&jar; -&zip; //#screenshot #ref(http://lh4.ggpht.com/_9Z4BYR88imo/TQTOo9LcVwI/AAAAAAAAAcs/fUEpKhXr_aI/s800/InternalFrameTitleBar.png) **サンプルコード [#k636189e] #code(link){{ final JInternalFrame internal = new JInternalFrame("@title@"); BasicInternalFrameUI ui = (BasicInternalFrameUI)internal.getUI(); Component title = ui.getNorthPane(); for(MouseMotionListener l:title.getListeners(MouseMotionListener.class)) { title.removeMouseMotionListener(l); } DragWindowListener dwl = new DragWindowListener(); title.addMouseListener(dwl); title.addMouseMotionListener(dwl); JPanel p = new JPanel(new BorderLayout()); p.add(new JScrollPane(new JTree())); p.add(new JButton(new AbstractAction("close") { @Override public void actionPerformed(ActionEvent e) { Window w = SwingUtilities.windowForComponent((Component)e.getSource()); //w.dispose(); w.getToolkit().getSystemEventQueue().postEvent( new WindowEvent(w, WindowEvent.WINDOW_CLOSING)); } }), BorderLayout.SOUTH); internal.getContentPane().add(p); internal.setVisible(true); KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if("activeWindow".equals(prop)) { try{ internal.setSelected(e.getNewValue()!=null); }catch(PropertyVetoException ex) { ex.printStackTrace(); } } } }); }} **解説 [#d219693c] 上記のサンプルでは、``JInternalFrame``のタイトルバーを使用することで、タイトルバーに閉じるボタンのないフレームを作成しています。 -``JFrame#setUndecorated(true)``で、``JFrame``のタイトルバーなどを非表示 -``BasicInternalFrameUI#getNorthPane()``で``JInternalFrame``のタイトルバーを取得 --元の``MouseMotionListener``を削除 --``JInternalFrame``をドラッグすると親の``JFrame``が移動する``MouseMotionListener``を追加 -制限 --最大化、最小化、リサイズなどには未対応 ---``Alt+Space``で最大化、最小化できるが、元のサイズに戻せなくなる場合がある --角の透明化には未対応 ---目立たなくするために、``LookAndFeel``は``Nimbus``に変更 ---``JDK 1.7.0``なら、``frame.setBackground(new Color(0,0,0,0)); frame.add(p=new MainPanel()); p.setOpaque(false);``で角の透明化が可能 **参考リンク [#y4fccd48] - [[JWindowをマウスで移動>Swing/DragWindow]] - [[JFrameのタイトルバーなどの装飾を独自のものにカスタマイズする>Swing/CustomDecoratedFrame]] - [[JRootPaneにリサイズのための装飾を設定する>Swing/WindowDecorationStyle]] **コメント [#b720b8d7] - ``JFrame``のアクティブ状態が変わったら、``JInternalFrame``の選択状態も変化するように変更。 -- [[aterai]] &new{2009-11-13 (金) 14:57:18}; - リサイズ可能?にする場合のテスト。 -- [[aterai]] &new{2010-06-10 (木) 15:07:18}; -- [[JRootPaneにリサイズのための装飾を設定する>Swing/WindowDecorationStyle]]に移動。 -- [[aterai]] &new{2013-06-17 (月) 02:29:47}; #comment