Swing/KeepHiddenDivider のバックアップ差分(No.4)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/KeepHiddenDivider へ行く。
- 1 (2010-07-26 (月) 06:35:29)
- 2 (2011-04-22 (金) 17:38:21)
- 3 (2012-11-23 (金) 04:41:40)
- 4 (2012-12-29 (土) 07:31:19)
- 5 (2013-02-01 (金) 20:14:58)
- 6 (2014-10-25 (土) 23:50:18)
- 7 (2014-11-01 (土) 00:46:09)
- 8 (2015-01-03 (土) 06:23:03)
- 9 (2016-06-07 (火) 14:40:17)
- 10 (2017-04-07 (金) 13:51:51)
- 11 (2017-09-16 (土) 14:57:22)
- 12 (2017-11-02 (木) 15:34:40)
- 13 (2019-03-14 (木) 13:49:22)
- 14 (2020-12-23 (水) 12:31:28)
- 15 (2022-08-20 (土) 22:15:25)
- 16 (2023-06-01 (木) 14:47:59)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JSplitPaneの収納状態を維持する
#navi(../)
#tags()
RIGHT:Posted by &author(aterai); at 2010-07-26
*JSplitPaneの収納状態を維持する [#uaf1fd86]
JSplitPaneのサイズが変更されても、ディバイダの収納状態を維持するように設定します。
-&jnlp;
-&jar;
-&zip;
//#screenshot
#ref(http://lh5.ggpht.com/_9Z4BYR88imo/TQTOy71x7HI/AAAAAAAAAc8/gLDHiIJS_Yw/s800/KeepHiddenDivider.png)
**サンプルコード [#uf26d930]
#code(link){{
final Container divider = ((BasicSplitPaneUI)splitPane.getUI()).getDivider();
ButtonModel selectMinModel = null;
ButtonModel selectMaxModel = null;
for(Component c: divider.getComponents()) {
if(c instanceof JButton) {
ButtonModel m = ((JButton)c).getModel();
if(selectMinModel==null && selectMaxModel==null) {
selectMinModel = m;
}else if(selectMaxModel==null) {
selectMaxModel = m;
}
}
}
JButton smin = new JButton("Min:keepHidden");
smin.setModel(selectMinModel);
JButton smax = new JButton("Max:keepHidden");
smax.setModel(selectMaxModel);
}}
**解説 [#s4ccc36a]
- Min:DividerLocation, Max:DividerLocation
-- JSplitPane#setDividerLocation メソッドでDividerの位置を設定
-- JSplitPaneのリサイズで収納状態が解除される
#code{{
panel.add(new JButton(new AbstractAction("Min:DividerLocation") {
@Override public void actionPerformed(ActionEvent e) {
splitPane.setDividerLocation(0);
}
}));
}}
- Min:Action, Max:Action
-- JSplitPaneのActionMapから"selectMax"アクションなどを取得し実行
-- JSplitPaneのリサイズで収納状態が解除される
#code{{
panel.add(new JButton(new AbstractAction("Max:Action") {
@Override public void actionPerformed(final ActionEvent e) {
splitPane.requestFocusInWindow();
EventQueue.invokeLater(new Runnable() {
@Override public void run() {
Action selectMaxAction = splitPane.getActionMap().get("selectMax");
e.setSource(splitPane);
selectMaxAction.actionPerformed(e);
}
});
}
}));
}}
- Min:keepHidden, Max:keepHidden
-- Dividerに表示されているJButtonを取得し実行
-- JSplitPaneがリサイズされても収納状態は維持される
----
[http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5006095 Bug ID: 5006095 Need a way to programmatically stick JSplitPane divider under j2sdk 1.5]のようにリフレクションを使って、BasicSplitPaneUI#setKeepHidden(true)メソッドを実行して、収納状態を維持する方法もあります。
#code{{
try {
splitPane.setDividerLocation(0);
Method setKeepHidden = BasicSplitPaneUI.class.getDeclaredMethod(
"setKeepHidden", new Class[] { Boolean.class });
setKeepHidden.setAccessible(true);
setKeepHidden.invoke(splitPane.getUI(), new Object[] { Boolean.TRUE });
}catch(Exception e) {
e.printStackTrace();
}
}}
**参考リンク [#p81df09a]
-[http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5006095 Bug ID: 5006095 Need a way to programmatically stick JSplitPane divider under j2sdk 1.5]
-[[JSplitPaneのディバイダを展開、収納する>Swing/OneTouchExpandable]]
**コメント [#z926bfc1]
#comment