Java Code Examples for javax.swing.JTree#setExpandsSelectedPaths()
The following examples show how to use
javax.swing.JTree#setExpandsSelectedPaths() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From IBC with GNU General Public License v3.0 | 6 votes |
/** * Selects the specified section in the Global Configuration dialog. * @param configDialog * the Global Configuration dialog * @param path * the path to the required configuration section in the Global Configuration dialog * @return * true if the specified section can be found; otherwise false * @throws IbcException * a UI component could not be found * @throws IllegalStateException * the method has not been called on the SWing event dispatch thread */ static boolean selectConfigSection(final JDialog configDialog, final String[] path) throws IbcException, IllegalStateException { if (!SwingUtilities.isEventDispatchThread()) throw new IllegalStateException("selectConfigSection must be run on the event dispatch thread"); JTree configTree = SwingUtils.findTree(configDialog); if (configTree == null) throw new IbcException("could not find the config tree in the Global Configuration dialog"); Object node = configTree.getModel().getRoot(); TreePath tp = new TreePath(node); for (String pathElement: path) { node = SwingUtils.findChildNode(configTree.getModel(), node, pathElement); if (node == null) return false; tp = tp.pathByAddingChild(node); } configTree.setExpandsSelectedPaths(true); configTree.setSelectionPath(tp); return true; }
Example 2
Source File: Utils.java From ib-controller with GNU General Public License v3.0 | 6 votes |
/** * Selects the specified section in the Global Configuration dialog. * @param configDialog * the Global Configuration dialog * @param path * the path to the required configuration section in the Global Configuration dialog * @return * true if the specified section can be found; otherwise false * @throws IBControllerException * a UI component could not be found * @throws IllegalStateException * the method has not been called on the SWing event dispatch thread */ static boolean selectConfigSection(final JDialog configDialog, final String[] path) throws IBControllerException, IllegalStateException { if (!SwingUtilities.isEventDispatchThread()) throw new IllegalStateException("selectConfigSection must be run on the event dispatch thread"); JTree configTree = SwingUtils.findTree(configDialog); if (configTree == null) throw new IBControllerException("could not find the config tree in the Global Configuration dialog"); Object node = configTree.getModel().getRoot(); TreePath tp = new TreePath(node); for (String pathElement: path) { node = SwingUtils.findChildNode(configTree.getModel(), node, pathElement); if (node == null) return false; tp = tp.pathByAddingChild(node); } configTree.setExpandsSelectedPaths(true); configTree.setSelectionPath(tp); return true; }
Example 3
Source File: WmsAssistantPage2.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override public Component createPageComponent() { JPanel panel = new JPanel(new BorderLayout(4, 4)); panel.setBorder(new EmptyBorder(4, 4, 4, 4)); panel.add(new JLabel("Available layers:"), BorderLayout.NORTH); LayerSourcePageContext context = getContext(); modelCRS = (CoordinateReferenceSystem) context.getLayerContext().getCoordinateReferenceSystem(); WMSCapabilities wmsCapabilities = (WMSCapabilities) context.getPropertyValue( WmsLayerSource.PROPERTY_NAME_WMS_CAPABILITIES); layerTree = new JTree(new WmsTreeModel(wmsCapabilities.getLayer())); layerTree.setRootVisible(false); layerTree.setShowsRootHandles(true); layerTree.setExpandsSelectedPaths(true); layerTree.setCellRenderer(new MyDefaultTreeCellRenderer()); layerTree.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); layerTree.getSelectionModel().addTreeSelectionListener(new LayerTreeSelectionListener()); panel.add(new JScrollPane(layerTree), BorderLayout.CENTER); infoLabel = new JLabel(" "); panel.add(infoLabel, BorderLayout.SOUTH); getContext().setPropertyValue(WmsLayerSource.PROPERTY_NAME_SELECTED_LAYER, null); return panel; }