Swing/ContinuousLayout のバックアップの現在との差分(No.9)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/ContinuousLayout へ行く。
- 1 (2012-12-29 (土) 07:33:42)
- 2 (2013-08-01 (木) 14:06:55)
- 3 (2013-08-17 (土) 01:09:13)
- 4 (2013-09-11 (水) 00:34:49)
- 5 (2014-10-25 (土) 23:48:10)
- 6 (2014-11-25 (火) 03:03:31)
- 7 (2015-02-14 (土) 10:17:07)
- 8 (2016-12-15 (木) 17:04:07)
- 9 (2017-12-06 (水) 14:02:18)
- 10 (2018-10-08 (月) 18:25:25)
- 11 (2020-10-03 (土) 14:12:15)
- 12 (2022-07-06 (水) 04:57:09)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- category: swing folder: ContinuousLayout title: JSplitPaneでディバイダの移動を連続的に再描画 tags: [JSplitPane, Divider, PropertyChangeListener] author: aterai pubdate: 2010-07-12T15:30:54+09:00 description: 二つのJSplitPaneのディバイダで、移動の同期と連続的な再描画を行います。 image: https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTKL-SYs6I/AAAAAAAAAVk/pXv9HlMSLf0/s800/ContinuousLayout.png --- * 概要 [#summary] 二つの`JSplitPane`のディバイダで、移動の同期と連続的な再描画を行います。 #download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTKL-SYs6I/AAAAAAAAAVk/pXv9HlMSLf0/s800/ContinuousLayout.png) * サンプルコード [#sourcecode] #code(link){{ final JSplitPane leftPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); final JSplitPane rightPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); final JSplitPane centerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); JSplitPane leftPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); JSplitPane rightPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); JSplitPane centerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); leftPane.setTopComponent(new JScrollPane(new JTextArea("aaaaaaa"))); leftPane.setBottomComponent(new JScrollPane(new JTextArea("bbbb"))); rightPane.setTopComponent(new JScrollPane(new JTree())); rightPane.setBottomComponent(new JScrollPane(new JTree())); centerPane.setLeftComponent(leftPane); centerPane.setRightComponent(rightPane); leftPane.setResizeWeight(.5); rightPane.setResizeWeight(.5); centerPane.setResizeWeight(.5); PropertyChangeListener pcl = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent e) { if (JSplitPane.DIVIDER_LOCATION_PROPERTY.equals(e.getPropertyName())) { JSplitPane source = (JSplitPane) e.getSource(); int location = ((Integer) e.getNewValue()).intValue(); JSplitPane target = (source == leftPane) ? rightPane : leftPane; if (location != target.getDividerLocation()) target.setDividerLocation(location); } } }; leftPane.addPropertyChangeListener(pcl); rightPane.addPropertyChangeListener(pcl); }} * 解説 [#explanation] 上記のサンプルでは、`JSplitPane`を`3`つ使用し、`4`つに分割された領域を表示しています。 上記のサンプルでは、各`JSplitPane`に`JSplitPane#setContinuousLayout(true)`を設定し、ディバイダの移動に応じて子コンポーネントを連続的に再描画しています。 ---- 左右に配置されたディバイダがマウスのドラッグに同期して移動するように、以下のように設定しています。 - `JSplitPane`を`3`つ使用し`4`つに分割された領域を表示 - 左右に配置されたディバイダがマウスのドラッグに同期して移動するように以下を設定 -- 片方のディバイダが上下移動したら残りも移動するように`PropertyChangeListener`を追加 -- `JSplitPane#setContinuousLayout(true)`を設定して移動を連続的に再描画 - 片方のディバイダが上下移動したら、残りも移動するように`PropertyChangeListener`を追加 - `JSplitPane#setContinuousLayout(true)`として、移動を連続的に再描画 * 参考リンク [#reference] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JSplitPane.html#setContinuousLayout-boolean- JSplitPane#setContinuousLayout(boolean) (Java Platform SE 8)] - [https://community.oracle.com/thread/1376808 Swing - Regading SplitPanes] * コメント [#comment] #comment #comment