Swing/InternalFrameTitleBar のバックアップの現在との差分(No.3)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - 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(../) RIGHT:Posted by [[terai]] at 2009-08-31 *JInternalFrameをJFrameとして表示する [#tf5e5ced] JFrameのタイトルバーなどを非表示にし、JInternalFrameのタイトルバーでこれらを代用します。 --- category: swing folder: InternalFrameTitleBar title: JInternalFrameをJFrameとして表示する tags: [JFrame, JInternalFrame, MouseListener, MouseMotionListener] author: aterai pubdate: 2009-08-31T15:27:18+09:00 description: JFrameのタイトルバーなどを非表示にし、JInternalFrameのタイトルバーでこれらを代用します。 image: https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTOo9LcVwI/AAAAAAAAAcs/fUEpKhXr_aI/s800/InternalFrameTitleBar.png hreflang: href: https://java-swing-tips.blogspot.com/2009/11/add-jinternalframe-to-undecorated.html lang: en --- * 概要 [#summary] `JFrame`のタイトルバーなどを非表示にし、`JInternalFrame`のタイトルバーでこれらを代用します。 -&jnlp; -&jar; -&zip; #download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTOo9LcVwI/AAAAAAAAAcs/fUEpKhXr_aI/s800/InternalFrameTitleBar.png) #screenshot **サンプルコード [#k636189e] #code{{ final JInternalFrame internal = new JInternalFrame("@title@"); BasicInternalFrameUI ui = (BasicInternalFrameUI)internal.getUI(); * サンプルコード [#sourcecode] #code(link){{ JInternalFrame internal = new JInternalFrame("@title@"); BasicInternalFrameUI ui = (BasicInternalFrameUI) internal.getUI(); Component title = ui.getNorthPane(); for(MouseMotionListener l:title.getListeners(MouseMotionListener.class)) { 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") { public void actionPerformed(ActionEvent e) { Window w = SwingUtilities.windowForComponent((Component)e.getSource()); @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)); new WindowEvent(w, WindowEvent.WINDOW_CLOSING)); } }), BorderLayout.SOUTH); internal.getContentPane().add(p); internal.setVisible(true); EventQueue.invokeLater(new Runnable() { public void run() { try{ internal.setSelected(true); }catch(java.beans.PropertyVetoException ex) { ex.printStackTrace(); KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener(e -> { String prop = e.getPropertyName(); if ("activeWindow".equals(prop)) { try { internal.setSelected(Objects.nonNull(e.getNewValue())); } catch (PropertyVetoException ex) { throw new IllegalStateException(ex); } } }); }} **解説 [#d219693c] 上記のサンプルでは、JInternalFrameのタイトルバーを使用することで、タイトルバーに閉じるボタンのないフレームを作成しています。 * 解説 [#explanation] 上記のサンプルでは、`JInternalFrame`のタイトルバーを使用することでタイトルバーに閉じるボタンのないフレームを作成しています。 -JFrame#setUndecorated(true) で、JFrameのタイトルバーなどを非表示 -BasicInternalFrameUI#getNorthPane()でJInternalFrameのタイトルバーを取得 --元のMouseMotionListenerを削除 --JInternalFrameをドラッグすると親のJFrameが移動するMouseMotionListenerを追加 - `JFrame#setUndecorated(true)`で`JFrame`のタイトルバーなどを非表示 - `BasicInternalFrameUI#getNorthPane()`で`JInternalFrame`のタイトルバーを取得 -- 元の`MouseMotionListener`を削除 -- `JInternalFrame`をドラッグすると親の`JFrame`が移動する`MouseMotionListener`を追加 - `JDK 1.7.0`以上の場合は`frame.setBackground(new Color(0x0, true)); frame.add(p = new MainPanel()); p.setOpaque(false);`で角の透明化が可能 - 最大化、最小化、リサイズなどには未対応 -- KBD{Alt+Space}で最大化、最小化できるが、元のサイズに戻せなくなる場合がある - %%角の透明化には未対応%% -- 目立たなくするために、`LookAndFeel`は`Nimbus`に変更 -制限 --最大化、最小化、リサイズなどには未対応 ---Alt+Spaceで最大化、最小化できるが、元のサイズに戻せなくなる場合がある --角の透明化には未対応 ---目立たなくするために、LookAndFeelはNimbusに変更 * 参考リンク [#reference] - [[JWindowをマウスで移動>Swing/DragWindow]] - [[JFrameのタイトルバーなどの装飾を独自のものにカスタマイズする>Swing/CustomDecoratedFrame]] - [[JRootPaneにリサイズのための装飾を設定する>Swing/WindowDecorationStyle]] //**参考リンク **コメント [#b720b8d7] * コメント [#comment] #comment - `JFrame`のアクティブ状態が変わったら、`JInternalFrame`の選択状態も変化するように変更。 -- &user(aterai); &new{2009-11-13 (金) 14:57:18}; - リサイズ可能?にする場合のテスト。 -- &user(aterai); &new{2010-06-10 (木) 15:07:18}; -- [[JRootPaneにリサイズのための装飾を設定する>Swing/WindowDecorationStyle]]に移動。 -- &user(aterai); &new{2013-06-17 (月) 02:29:47}; #comment