Swing/DetailsViewFileChooser のバックアップの現在との差分(No.8)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/DetailsViewFileChooser へ行く。
- 1 (2011-01-10 (月) 17:02:55)
- 2 (2011-01-10 (月) 22:39:33)
- 3 (2011-01-12 (水) 16:04:36)
- 4 (2011-01-13 (木) 15:15:37)
- 5 (2012-12-23 (日) 05:27:57)
- 6 (2013-04-30 (火) 18:11:09)
- 7 (2015-01-08 (木) 14:00:23)
- 8 (2016-04-27 (水) 20:11:20)
- 9 (2016-05-26 (木) 14:43:16)
- 10 (2017-04-07 (金) 13:51:51)
- 11 (2017-08-18 (金) 14:49:03)
- 12 (2017-11-02 (木) 15:32:16)
- 13 (2018-08-21 (火) 14:24:26)
- 14 (2019-01-18 (金) 17:22:00)
- 15 (2020-11-26 (木) 11:39:38)
- 16 (2022-03-08 (火) 19:33:13)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- category: swing folder: DetailsViewFileChooser title: JFileChooserのデフォルトをDetails Viewに設定 tags: [JFileChooser, FilePane] author: aterai pubdate: 2011-01-10T17:02:55+09:00 description: JFileChooserを開いたときのデフォルトをリストではなく詳細に変更します。 image: https://lh3.googleusercontent.com/_9Z4BYR88imo/TSq77M-soeI/AAAAAAAAAxg/0nnen-n-cAY/s800/DetailsViewFileChooser.png --- * 概要 [#f6a8221b] * 概要 [#summary] `JFileChooser`を開いたときのデフォルトをリストではなく詳細に変更します。 #download(https://lh3.googleusercontent.com/_9Z4BYR88imo/TSq77M-soeI/AAAAAAAAAxg/0nnen-n-cAY/s800/DetailsViewFileChooser.png) * サンプルコード [#bb304f2a] * サンプルコード [#sourcecode] #code(link){{ //java - How can I start the JFileChooser in the Details view? - Stack Overflow] //http://stackoverflow.com/questions/16292502/how-can-i-start-the-jfilechooser-in-the-details-view //for (Object key: chooser.getActionMap().allKeys()) { // System.out.println(key); //} Action detailsAction = chooser.getActionMap().get("viewTypeDetails"); if (detailsAction != null) { detailsAction.actionPerformed(null); } // java - How can I start the JFileChooser in the Details view? - Stack Overflow] // https://stackoverflow.com/questions/16292502/how-can-i-start-the-jfilechooser-in-the-details-view // for (Object key: chooser.getActionMap().allKeys()) { // System.out.println(key); // } String cmd = "viewTypeDetails"; Optional.ofNullable(chooser.getActionMap().get(cmd)) .ifPresent(a -> a.actionPerformed(new ActionEvent(e.getSource(), e.getID(), cmd))); }} * 解説 [#d6cd620d] - 以下のリンクで紹介されているように、`ActionMap`から`viewTypeDetails`アクションを取得する方法が一番簡単なようです。 -- [http://stackoverflow.com/questions/16292502/how-can-i-start-the-jfilechooser-in-the-details-view java - How can I start the JFileChooser in the Details view? - Stack Overflow] -- 何時から使用できるようになったのか、それとも元から使用可能だったのかなどを調査中。 * 解説 [#explanation] - [https://stackoverflow.com/questions/16292502/how-can-i-start-the-jfilechooser-in-the-details-view java - How can I start the JFileChooser in the Details view? - Stack Overflow]で紹介されている`ActionMap`から`viewTypeDetails`アクションを取得して`DetailsView`(詳細)に切り替え ---- `JFileChooser`の子で`UIManager.getIcon("FileChooser.detailsViewIcon")`アイコンが設定されている`JToggleButton`を検索、`doClick()`することで、`List`から`DetailsView`(詳細)に切り替える方法もあります。 #code{{ // @see javax/swing/plaf/basic/BasicFileChooserUI.java ActionMap map = new ActionMapUIResource(); Action refreshAction = new UIAction(FilePane.ACTION_REFRESH) { public void actionPerformed(ActionEvent e) { getFileChooser().rescanCurrentDirectory(); } }; map.put(FilePane.ACTION_APPROVE_SELECTION, getApproveSelectionAction()); map.put(FilePane.ACTION_CANCEL, getCancelSelectionAction()); map.put(FilePane.ACTION_REFRESH, refreshAction); map.put(FilePane.ACTION_CHANGE_TO_PARENT_DIRECTORY, getChangeToParentDirectoryAction()); // sun.swing.FilePane.ACTION_APPROVE_SELECTION = "approveSelection"; // sun.swing.FilePane.ACTION_CANCEL = "cancelSelection"; // sun.swing.FilePane.ACTION_EDIT_FILE_NAME = "editFileName"; // sun.swing.FilePane.ACTION_REFRESH = "refresh"; // sun.swing.FilePane.ACTION_CHANGE_TO_PARENT_DIRECTORY = "Go Up"; // sun.swing.FilePane.ACTION_NEW_FOLDER = "New Folder"; // sun.swing.FilePane.ACTION_VIEW_LIST = "viewTypeList"; // sun.swing.FilePane.ACTION_VIEW_DETAILS = "viewTypeDetails"; }} - `MetalLookAndFeel`などの`JFileChooser`の子で`UIManager.getIcon("FileChooser.detailsViewIcon")`アイコンが設定されている`JToggleButton`を検索、`doClick()`することで`List`から`DetailsView`(詳細)に切り替え -- `WindowsLookAndFeel`での`JFileChooser`の`DetailsView`切り替えは`JRadioButtonMenuItem`なのでこの方法は使用不可 #code{{ //searchAndClick(chooser, UIManager.getIcon("FileChooser.detailsViewIcon")); // searchAndClick(chooser, UIManager.getIcon("FileChooser.detailsViewIcon")); private static boolean searchAndClick(Container parent, Icon icon) { for (Component c:parent.getComponents()) { if (c instanceof JToggleButton && ((JToggleButton) c).getIcon() == icon) { ((AbstractButton) c).doClick(); return true; } else { if (searchAndClick((Container) c, icon)) { return true; } } } return false; } }} ---- 警告されますが、以下のように`sun.swing.FilePane#setViewType(sun.swing.FilePane.VIEWTYPE_DETAILS)`メソッドを使用する方法もあります。 - 警告されるが以下のように`sun.swing.FilePane#setViewType(sun.swing.FilePane.VIEWTYPE_DETAILS)`メソッドを使用する方法もある #code{{ FilePane filePane = (FilePane) findChildComponent(chooser, FilePane.class); filePane.setViewType(FilePane.VIEWTYPE_DETAILS); }} * 参考リンク [#k11fb09b] - [http://stackoverflow.com/questions/16292502/how-can-i-start-the-jfilechooser-in-the-details-view java - How can I start the JFileChooser in the Details view? - Stack Overflow] - [http://tips4java.wordpress.com/2008/11/13/swing-utils/ Swing Utils « Java Tips Weblog] * 参考リンク [#reference] - [https://stackoverflow.com/questions/16292502/how-can-i-start-the-jfilechooser-in-the-details-view java - How can I start the JFileChooser in the Details view? - Stack Overflow] - [https://tips4java.wordpress.com/2008/11/13/swing-utils/ Swing Utils « Java Tips Weblog] -- via: [http://www.java-forums.org/awt-swing/13733-set-jfilechooser-default-details-view.html set jFileChooser default to details view - Java Forums] - [http://www.docjar.com/html/api/sun/swing/FilePane.java.html sun.swing: FilePane.java] * コメント [#k2202d2b] * コメント [#comment] #comment #comment