Example usage for javax.swing JTree JTree

List of usage examples for javax.swing JTree JTree

Introduction

In this page you can find the example usage for javax.swing JTree JTree.

Prototype

@ConstructorProperties({ "model" })
public JTree(TreeModel newModel) 

Source Link

Document

Returns an instance of JTree which displays the root node -- the tree is created using the specified data model.

Usage

From source file:BasicDnD.java

public BasicDnD() {
    super(new BorderLayout());
    JPanel leftPanel = createVerticalBoxPanel();
    JPanel rightPanel = createVerticalBoxPanel();

    //Create a table model.
    DefaultTableModel tm = new DefaultTableModel();
    tm.addColumn("Column 0");
    tm.addColumn("Column 1");
    tm.addColumn("Column 2");
    tm.addColumn("Column 3");
    tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" });
    tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" });
    tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" });
    tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" });

    //LEFT COLUMN
    //Use the table model to create a table.
    table = new JTable(tm);
    leftPanel.add(createPanelForComponent(table, "JTable"));

    //Create a color chooser.
    colorChooser = new JColorChooser();
    leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser"));

    //RIGHT COLUMN
    //Create a textfield.
    textField = new JTextField(30);
    textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast");
    rightPanel.add(createPanelForComponent(textField, "JTextField"));

    //Create a scrolled text area.
    textArea = new JTextArea(5, 30);
    textArea.setText("Favorite shows:\nBuffy, Alias, Angel");
    JScrollPane scrollPane = new JScrollPane(textArea);
    rightPanel.add(createPanelForComponent(scrollPane, "JTextArea"));

    //Create a list model and a list.
    DefaultListModel listModel = new DefaultListModel();
    listModel.addElement("Martha Washington");
    listModel.addElement("Abigail Adams");
    listModel.addElement("Martha Randolph");
    listModel.addElement("Dolley Madison");
    listModel.addElement("Elizabeth Monroe");
    listModel.addElement("Louisa Adams");
    listModel.addElement("Emily Donelson");
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    JScrollPane listView = new JScrollPane(list);
    listView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(listView, "JList"));

    //Create a tree.
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia");
    DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon");
    rootNode.add(sharon);//from w  ww  . j a  va  2s.  c o m
    DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya");
    sharon.add(maya);
    DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya");
    sharon.add(anya);
    sharon.add(new DefaultMutableTreeNode("Bongo"));
    maya.add(new DefaultMutableTreeNode("Muffin"));
    anya.add(new DefaultMutableTreeNode("Winky"));
    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    tree = new JTree(model);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    JScrollPane treeView = new JScrollPane(tree);
    treeView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(treeView, "JTree"));

    //Create the toggle button.
    toggleDnD = new JCheckBox("Turn on Drag and Drop");
    toggleDnD.setActionCommand("toggleDnD");
    toggleDnD.addActionListener(this);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
    splitPane.setOneTouchExpandable(true);

    add(splitPane, BorderLayout.CENTER);
    add(toggleDnD, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:TreeUtil.java

public JTree getTree(DefaultMutableTreeNode node) {
    JTree tree = new JTree(node);
    // tree.addTreeSelectionListener(this);
    return tree;/*from   w  w w  .  jav a2  s.co m*/
}

From source file:cloud.gui.CloudGUI.java

private void createELBTab() {
    elbTab = new JPanel();
    elbTab.setLayout(new GridLayout(1, 1));

    DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode("Elastic Load Balancer Table");
    elbTree = new JTree(treeRoot);

    elbTab.add(elbTree);//from   ww w  .ja v a2  s. co  m
    tabbedPane.addTab("Load Balancer", elbTab);
}

From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java

public void updateView(GradleNode rootDependency, GradleNode selectedDependency) {
    // TODO replace this hack with something that populates the GradleNode graph

    DefaultMutableTreeNode fullRoot = new DefaultMutableTreeNode(new GradleNode("Project Dependencies"));
    if (rootDependency == null) {
        DefaultMutableTreeNode loading = new DefaultMutableTreeNode(new GradleNode("Loading..."));
        fullRoot.add(loading);//from w  w w.  j  a  v a2s. com
    } else {
        DefaultMutableTreeNode flattenedRoot = convertToSortedTreeNode(rootDependency);
        DefaultMutableTreeNode hierarchyRoot = convertToHierarchyTreeNode(rootDependency);
        fullRoot.add(flattenedRoot);
        fullRoot.add(hierarchyRoot);
    }

    TreeModel treeModel = new DefaultTreeModel(fullRoot);
    final JTree fullTree = new JTree(treeModel);
    fullTree.setCellRenderer(dependencyCellRenderer);

    // expand path for first level from root
    //fullTree.expandPath(new TreePath(hierarchyRoot.getNextNode().getPath()));

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if (gradleBaseDir != null) {
                setTitle(TITLE + " - " + gradleBaseDir);
            }
            splitter.setLeftComponent(new JScrollPane(fullTree));
            splitter.setRightComponent(new JScrollPane(information));
            splitter.setDividerLocation(0.75);
        }
    });
}

From source file:hr.fer.zemris.vhdllab.view.explorer.ProjectExplorerView.java

@Override
protected JComponent createControl() {
    CommandManager commandManager = getActiveWindow().getCommandManager();
    commandManager.createCommandGroup("hierarchyMenu", new String[] { hierarchyXUsesYCommand.getId(),
            hierarchyXUsedByYCommand.getId(), hierarchyFlatCommand.getId() });
    CommandGroup commandGroup = commandManager.createCommandGroup("treePopupMenu",
            new String[] { "newMenu", "separator", openCommand.getId(), "separator", compileCommand.getId(),
                    simulateCommand.getId(), viewVhdlCommand.getId(), "separator", deleteCommand.getId(),
                    "separator", "hierarchyMenu" });
    popupMenu = commandGroup.createPopupMenu();

    root = new DefaultMutableTreeNode("vhdllab-root");
    model = new DefaultTreeModel(root);
    model.addTreeModelListener(new TreeModelAdapter() {
        @Override/*from w  w  w  .j  ava2 s  . c om*/
        public void treeNodesInserted(TreeModelEvent e) {
            Object[] children = e.getChildren();
            if (children.length > 0) {
                Object child = children[children.length - 1];
                TreePath path = e.getTreePath().pathByAddingChild(child);
                tree.setSelectionPath(path);
            }
        }
    });
    tree = new JTree(model);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    // tree is expanded manually in OpenFileOrShowPopupMenuListener
    tree.setToggleClickCount(0);
    tree.setCellRenderer(new WorkspaceCellRenderer());
    tree.addMouseListener(new OpenFileOrShowPopupMenuListener());
    tree.addTreeSelectionListener(new CommandGuard());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    JPanel hierarchyPanel = new JPanel();
    hierarchyPanel.add(createHierarchyButton(hierarchyXUsesYCommand));
    hierarchyPanel.add(createHierarchyButton(hierarchyXUsedByYCommand));
    hierarchyPanel.add(createHierarchyButton(hierarchyFlatCommand));
    JPanel borderHierarchyPanel = new JPanel(new BorderLayout());
    borderHierarchyPanel.add(hierarchyPanel, BorderLayout.WEST);

    JPanel control = new JPanel(new BorderLayout());
    control.add(borderHierarchyPanel, BorderLayout.NORTH);
    control.add(new JScrollPane(tree), BorderLayout.CENTER);

    return control;
}

From source file:com.projity.pm.graphic.chart.ChartLegend.java

private void initTree() {
    //      tree = new JTree(chartInfo.getNodeModel());
    tree = new JTree(chartInfo.getCache());
    tree.setExpandsSelectedPaths(true);/* w ww .ja va 2  s.co  m*/
    final JTree finalTree = tree;
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            if (selecting)
                return;
            TreePath[] paths = ((JTree) evt.getSource()).getSelectionPaths(); //evt.getPaths();
            chartInfo.updateChart(selectedObjects, pathsToList(paths));
        }

    });
    tree.setCellRenderer(new TreeRenderer());
    if (treeScrollPane == null)
        treeScrollPane = new JScrollPane(tree);
    else
        treeScrollPane.getViewport().add(tree);
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * /*from w w  w  .  j  a v  a 2  s . co m*/
 */
protected void createUI() {
    JTabbedPane tabbedPane = new JTabbedPane();

    rp = new RegProcessor();
    rp.processSQL();

    tree = new JTree(rp.getRoot(INCL_ANON));
    propsTable = new JTable();

    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            fillPropsTable();
        }
    });
    tree.setCellRenderer(new MyTreeCellRenderer());

    Component topComp = UIHelper.createScrollPane(tree);
    Component botComp = UIHelper.createScrollPane(propsTable);
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComp, botComp);

    splitPane.setDividerLocation(0.5);
    splitPane.setOneTouchExpandable(true);

    splitPane.setLastDividerLocation(300);
    Dimension minimumSize = new Dimension(200, 400);
    topComp.setMinimumSize(minimumSize);
    botComp.setMinimumSize(minimumSize);

    tabbedPane.add("Registration", splitPane);

    final List<Pair<String, String>> trackDescPairs = rp.getTrackKeyDescPairs();
    Vector<String> trkItems = new Vector<String>();
    for (Pair<String, String> p : trackDescPairs) {
        trkItems.add(p.second);
    }

    //Collections.sort(trkItems);
    final JList list = new JList(trkItems);
    //pb.add(UIHelper.createScrollPane(list), cc.xy(1, 1));
    list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int inx = list.getSelectedIndex();
                if (inx > -1) {
                    fillUsageItemsList(trackDescPairs.get(inx).first);
                }
            }
        }
    });

    tabbedPane.add("Reg Stats", getStatsPane("Registration", rp.getRegNumHash().values(), "register"));

    DefaultListModel model = new DefaultListModel();
    trackItemsList = new JList(model);

    topComp = UIHelper.createScrollPane(list);
    botComp = UIHelper.createScrollPane(trackItemsList);
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComp, botComp);
    splitPane.setDividerLocation(0.5);
    splitPane.setOneTouchExpandable(true);

    topComp.setMinimumSize(minimumSize);
    botComp.setMinimumSize(minimumSize);

    splitPane.setDividerLocation(0.5);
    trackUsageHash = rp.getTrackCatsHash();
    tabbedPane.add("Usage Tracking", splitPane);

    tabbedPane.add("User Stats", getStatsPane("Tracking", rp.getTrackIdHash().values(), "track"));

    add(tabbedPane, BorderLayout.CENTER);
}

From source file:EditorPaneExample18.java

public EditorPaneExample18() {
    super("JEditorPane Example 18");

    pane = new JEditorPane();
    pane.setEditable(true); // Editable
    getContentPane().add(new JScrollPane(pane), "Center");

    // Add a menu bar
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);//ww w  .  j  av  a  2 s.c  om

    // Populate it
    createMenuBar();

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);
    c.gridy = 3;
    panel.add(new JLabel(LOAD_TIME), c);

    c.gridy = 4;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    onlineLoad = new JCheckBox("Online Load");
    panel.add(onlineLoad, c);
    onlineLoad.setSelected(true);
    onlineLoad.setForeground(typeLabel.getForeground());

    c.gridy = 5;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    editableBox = new JCheckBox("Editable JEditorPane");
    panel.add(editableBox, c);
    editableBox.setSelected(true);
    editableBox.setForeground(typeLabel.getForeground());

    c.gridy = 6;
    c.weightx = 0.0;
    JButton saveButton = new JButton("Save");
    panel.add(saveButton, c);
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            EditorKit kit = pane.getEditorKit();
            try {
                if (kit instanceof RTFEditorKit) {
                    kit.write(System.out, pane.getDocument(), 0, pane.getDocument().getLength());
                    System.out.flush();
                } else {
                    if (writer == null) {
                        writer = new OutputStreamWriter(System.out);
                        pane.write(writer);
                        writer.flush();
                    }
                    kit.write(writer, pane.getDocument(), 0, pane.getDocument().getLength());
                    writer.flush();
                }
            } catch (Exception e) {
                System.out.println("Write failed");
            }
        }
    });

    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;

    urlCombo = new JComboBox();
    panel.add(urlCombo, c);
    urlCombo.setEditable(true);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);
    timeLabel = new JLabel("");
    c.gridy = 3;
    panel.add(timeLabel, c);

    getContentPane().add(panel, "South");

    // Register a custom EditorKit for HTML
    ClassLoader loader = getClass().getClassLoader();
    if (loader != null) {
        // Java 2
        JEditorPane.registerEditorKitForContentType("text/html",
                "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit", loader);
    } else {
        // JDK 1.1
        JEditorPane.registerEditorKitForContentType("text/html",
                "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit");
    }

    // Allocate the empty tree model
    DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty");
    emptyModel = new DefaultTreeModel(emptyRootNode);

    // Create and place the heading tree
    tree = new JTree(emptyModel);
    tree.setPreferredSize(new Dimension(200, 200));
    getContentPane().add(new JScrollPane(tree), "East");

    // Change page based on combo selection
    urlCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (populatingCombo == true) {
                return;
            }
            Object selection = urlCombo.getSelectedItem();
            loadNewPage(selection);
        }
    });

    // Change editability based on the checkbox
    editableBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pane.setEditable(editableBox.isSelected());
            pane.revalidate();
            pane.repaint();
        }
    });

    // Listen for page load to complete
    pane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("page")) {
                loadComplete();
                displayLoadTime();
                populateCombo(findLinks(pane.getDocument(), null));
                TreeNode node = buildHeadingTree(pane.getDocument());
                tree.setModel(new DefaultTreeModel(node));

                createMenuBar();
                enableMenuBar(true);
                getRootPane().revalidate();

                enableInput();
                loadingPage = false;
            }
        }
    });

    // Listener for tree selection
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getNewLeadSelectionPath();
            if (path != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object userObject = node.getUserObject();
                if (userObject instanceof Heading) {
                    Heading heading = (Heading) userObject;
                    try {
                        Rectangle textRect = pane.modelToView(heading.getOffset());
                        textRect.y += 3 * textRect.height;
                        pane.scrollRectToVisible(textRect);
                    } catch (BadLocationException e) {
                    }
                }
            }
        }
    });

    // Listener for hypertext events
    pane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            // Ignore hyperlink events if the frame is busy
            if (loadingPage == true) {
                return;
            }
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                JEditorPane sp = (JEditorPane) evt.getSource();
                if (evt instanceof HTMLFrameHyperlinkEvent) {
                    HTMLDocument doc = (HTMLDocument) sp.getDocument();
                    doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt);
                } else {
                    loadNewPage(evt.getURL());
                }
            } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                pane.setCursor(handCursor);
            } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
                pane.setCursor(defaultCursor);
            }
        }
    });
}

From source file:e3fraud.gui.MainWindow.java

public MainWindow() {
    super(new BorderLayout(5, 5));

    extended = false;//from w  ww  . j a  v a 2  s .  c  o m

    //Create the log first, because the action listeners
    //need to refer to it.
    log = new JTextArea(10, 50);
    log.setMargin(new Insets(5, 5, 5, 5));
    log.setEditable(false);
    logScrollPane = new JScrollPane(log);
    DefaultCaret caret = (DefaultCaret) log.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    //        create the progress bar
    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(progressBar.getMinimum());
    progressBar.setVisible(false);
    progressBar.setStringPainted(true);
    //Create the settings pane
    generationSettingLabel = new JLabel("Generate:");
    SpinnerModel collusionsSpinnerModel = new SpinnerNumberModel(1, 0, 3, 1);
    collusionSettingsPanel = new JPanel(new FlowLayout()) {
        @Override
        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    // collusionSettingsPanel.setLayout(new BoxLayout(collusionSettingsPanel, BoxLayout.X_AXIS));
    collusionsButton = new JSpinner(collusionsSpinnerModel);
    collusionsLabel = new JLabel("collusion(s)");
    collusionSettingsPanel.add(collusionsButton);
    collusionSettingsPanel.add(collusionsLabel);

    rankingSettingLabel = new JLabel("Rank by:");
    lossButton = new JRadioButton("loss");
    lossButton.setToolTipText("Sort sub-ideal models based on loss for Target of Assessment (high -> low)");
    gainButton = new JRadioButton("gain");
    gainButton.setToolTipText(
            "Sort sub-ideal models based on gain of any actor except Target of Assessment (high -> low)");
    lossGainButton = new JRadioButton("loss + gain");
    lossGainButton.setToolTipText(
            "Sort sub-ideal models based on loss for Target of Assessment and, if equal, on gain of any actor except Target of Assessment");
    //gainLossButton = new JRadioButton("gain + loss");
    lossGainButton.setSelected(true);
    rankingGroup = new ButtonGroup();
    rankingGroup.add(lossButton);
    rankingGroup.add(gainButton);
    rankingGroup.add(lossGainButton);
    //rankingGroup.add(gainLossButton);
    groupingSettingLabel = new JLabel("Group by:");
    groupingButton = new JCheckBox("collusion");
    groupingButton.setToolTipText(
            "Groups sub-ideal models based on the pair of actors colluding before ranking them");
    groupingButton.setSelected(false);
    refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(this);

    settingsPanel = new JPanel();
    settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.PAGE_AXIS));
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(generationSettingLabel);
    collusionSettingsPanel.setAlignmentX(LEFT_ALIGNMENT);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(collusionSettingsPanel);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    rankingSettingLabel.setAlignmentY(TOP_ALIGNMENT);
    settingsPanel.add(rankingSettingLabel);
    settingsPanel.add(lossButton);
    settingsPanel.add(gainButton);
    settingsPanel.add(lossGainButton);
    //settingsPanel.add(gainLossButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(groupingSettingLabel);
    settingsPanel.add(groupingButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(refreshButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
    progressBar.setPreferredSize(
            new Dimension(settingsPanel.getSize().width, progressBar.getPreferredSize().height));
    settingsPanel.add(progressBar);

    //Create the result tree
    root = new DefaultMutableTreeNode("No models to display");
    treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel);
    //tree.setUI(new CustomTreeUI());
    tree.setCellRenderer(new CustomTreeCellRenderer(tree));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setLargeModel(true);
    resultScrollPane = new JScrollPane(tree);
    tree.addTreeSelectionListener(treeSelectionListener);

    //tree.setShowsRootHandles(true);
    //Create a file chooser for saving
    sfc = new JFileChooser();
    FileFilter jpegFilter = new FileNameExtensionFilter("JPEG image", new String[] { "jpg", "jpeg" });
    sfc.addChoosableFileFilter(jpegFilter);
    sfc.setFileFilter(jpegFilter);

    //Create a file chooser for loading
    fc = new JFileChooser();
    FileFilter rdfFilter = new FileNameExtensionFilter("RDF file", "RDF");
    fc.addChoosableFileFilter(rdfFilter);
    fc.setFileFilter(rdfFilter);

    //Create the open button.  
    openButton = new JButton("Load model", createImageIcon("images/Open24.png"));
    openButton.addActionListener(this);
    openButton.setToolTipText("Load a e3value model");

    //Create the ideal graph button. 
    idealGraphButton = new JButton("Show ideal graph", createImageIcon("images/Plot.png"));
    idealGraphButton.setToolTipText("Display ideal profitability graph");
    idealGraphButton.addActionListener(this);

    Dimension thinButtonDimension = new Dimension(15, 420);

    //Create the expand subideal graph button. 
    expandButton = new JButton(">");
    expandButton.setPreferredSize(thinButtonDimension);
    expandButton.setMargin(new Insets(0, 0, 0, 0));
    expandButton.setToolTipText("Expand to show non-ideal profitability graph for selected model");
    expandButton.addActionListener(this);

    //Create the collapse sub-ideal graph button. 
    collapseButton = new JButton("<");
    collapseButton.setPreferredSize(thinButtonDimension);
    collapseButton.setMargin(new Insets(0, 0, 0, 0));
    collapseButton.setToolTipText("Collapse non-ideal profitability graph for selected model");
    collapseButton.addActionListener(this);

    //Create the generation button. 
    generateButton = new JButton("Generate sub-ideal models", createImageIcon("images/generate.png"));
    generateButton.addActionListener(this);
    generateButton.setToolTipText("Generate sub-ideal models for the e3value model currently loaded");

    //Create the chart panel
    chartPane = new JPanel();
    chartPane.setLayout(new FlowLayout(FlowLayout.LEFT));
    chartPane.add(expandButton);

    //For layout purposes, put the buttons in a separate panel
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(openButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(20, 0)));
    buttonPanel.add(generateButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPanel.add(idealGraphButton);

    //Add the buttons, the ranking options, the result list and the log to this panel.
    add(buttonPanel, BorderLayout.PAGE_START);
    add(settingsPanel, BorderLayout.LINE_START);
    add(resultScrollPane, BorderLayout.CENTER);

    add(logScrollPane, BorderLayout.PAGE_END);
    add(chartPane, BorderLayout.LINE_END);
    //and make a nice border around it
    setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10));
}

From source file:be.fedict.eid.tsl.tool.TslInternalFrame.java

private void addServiceProviderTab(JTabbedPane tabbedPane) {
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    tabbedPane.add("Service Providers", splitPane);

    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Service Providers");
    this.tree = new JTree(rootNode);
    this.tree.addTreeSelectionListener(this);
    for (TrustServiceProvider trustServiceProvider : this.trustServiceList.getTrustServiceProviders()) {
        DefaultMutableTreeNode trustServiceProviderNode = new DefaultMutableTreeNode(
                trustServiceProvider.getName());
        rootNode.add(trustServiceProviderNode);
        for (TrustService trustService : trustServiceProvider.getTrustServices()) {
            MutableTreeNode trustServiceNode = new DefaultMutableTreeNode(trustService);
            trustServiceProviderNode.add(trustServiceNode);
        }// www .j  a v  a2 s.c o m
    }
    this.tree.expandRow(0);

    JScrollPane treeScrollPane = new JScrollPane(this.tree);
    JPanel detailsPanel = new JPanel();
    splitPane.setLeftComponent(treeScrollPane);
    splitPane.setRightComponent(detailsPanel);

    initDetailsPanel(detailsPanel);
}