How can I select multiple nodes by standard

I want to ask how can I modify this example code to enable multiple selection, say if I select node1, system out display node1, then ctr+node2 selection. system out display node1&node2.
The code below, only display node1, then when I do ctr+node2 selection, system out still display node1.
I am quite new to JTree, so, please if there is anyone can give a solution?
Thanks
* A 1.4 application that requires the following additional files:
*   TreeDemoHelp.html
*    arnold.html
*    bloch.html
*    chan.html
*    jls.html
*    swingtutorial.html
*    tutorial.html
*    tutorialcont.html
*    vm.html
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.UIManager;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import java.net.URL;
import java.io.IOException;
import java.awt.Dimension;
import java.awt.GridLayout;
public class TreeDemo extends JPanel
                      implements TreeSelectionListener {
    private JEditorPane htmlPane;
    private JTree tree;
    private URL helpURL;
    private static boolean DEBUG = false;
    //Optionally play with line styles.  Possible values are
//  "Angled" (the default), "Horizontal", and "None".
    private static boolean playWithLineStyle = false;
    private static String lineStyle = "Horizontal";
    //Optionally set the look and feel.
    private static boolean useSystemLookAndFeel = false;
    public TreeDemo() {
        super(new GridLayout(1,0));
        //Create the nodes.
        DefaultMutableTreeNode top =
            new DefaultMutableTreeNode("The Java Series");
        createNodes(top);
        //Create a tree that allows one selection at a time.
        tree = new JTree(top);
        tree.getSelectionModel().setSelectionMode
                (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);---->Cause problem, when press Ctr to multiple select, always the first selected node is returned, which is shown in System out
        //Listen for when the selection changes.
        tree.addTreeSelectionListener(this);
        if (playWithLineStyle) {
            System.out.println("line style = " + lineStyle);
            tree.putClientProperty("JTree.lineStyle", lineStyle);
        //Create the scroll pane and add the tree to it.
        JScrollPane treeView = new JScrollPane(tree);
        //Create the HTML viewing pane.
        htmlPane = new JEditorPane();
        htmlPane.setEditable(false);
        initHelp();
        JScrollPane htmlView = new JScrollPane(htmlPane);
        //Add the scroll panes to a split pane.
        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        splitPane.setTopComponent(treeView);
        splitPane.setBottomComponent(htmlView);
        Dimension minimumSize = new Dimension(100, 50);
        htmlView.setMinimumSize(minimumSize);
        treeView.setMinimumSize(minimumSize);
        splitPane.setDividerLocation(100); //XXX: ignored in some releases
                                           //of Swing. bug 4101306
        //workaround for bug 4101306:
        //treeView.setPreferredSize(new Dimension(100, 100));
        splitPane.setPreferredSize(new Dimension(500, 300));
        //Add the split pane to this panel.
        add(splitPane);
    /** Required by TreeSelectionListener interface. */
    public void valueChanged(TreeSelectionEvent e) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                           tree.getLastSelectedPathComponent();
        if (node == null) return;
        Object nodeInfo = node.getUserObject();
        System.out.print("\nMy selection node is"+nodeInfo.toString());
        if (node.isLeaf()) {
            BookInfo book = (BookInfo)nodeInfo;
            displayURL(book.bookURL);
            if (DEBUG) {
                System.out.print(book.bookURL + ":  \n    ");
        } else {
            displayURL(helpURL);
        if (DEBUG) {
            System.out.println(nodeInfo.toString());
    private class BookInfo {
        public String bookName;
        public URL bookURL;
        public BookInfo(String book, String filename) {
            bookName = book;
            bookURL = TreeDemo.class.getResource(filename);
            if (bookURL == null) {
                System.err.println("Couldn't find file: "
                                   + filename);
        public String toString() {
            return bookName;
    private void initHelp() {
        String s = "TreeDemoHelp.html";
        helpURL = TreeDemo.class.getResource(s);
        if (helpURL == null) {
            System.err.println("Couldn't open help file: " + s);
        } else if (DEBUG) {
            System.out.println("Help URL is " + helpURL);
        displayURL(helpURL);
    private void displayURL(URL url) {
        try {
            if (url != null) {
                htmlPane.setPage(url);
            } else { //null url
          htmlPane.setText("File Not Found");
                if (DEBUG) {
                    System.out.println("Attempted to display a null URL.");
        } catch (IOException e) {
            System.err.println("Attempted to read a bad URL: " + url);
    private void createNodes(DefaultMutableTreeNode top) {
        DefaultMutableTreeNode category = null;
        DefaultMutableTreeNode book = null;
        category = new DefaultMutableTreeNode("Books for Java Programmers");
        top.add(category);
        //original Tutorial
        book = new DefaultMutableTreeNode(new BookInfo
            ("The Java Tutorial: A Short Course on the Basics",
            "tutorial.html"));
        category.add(book);
        //Tutorial Continued
        book = new DefaultMutableTreeNode(new BookInfo
            ("The Java Tutorial Continued: The Rest of the JDK",
            "tutorialcont.html"));
        category.add(book);
        //JFC Swing Tutorial
        book = new DefaultMutableTreeNode(new BookInfo
            ("The JFC Swing Tutorial: A Guide to Constructing GUIs",
            "swingtutorial.html"));
        category.add(book);
        //Bloch
        book = new DefaultMutableTreeNode(new BookInfo
            ("Effective Java Programming Language Guide",
          "bloch.html"));
        category.add(book);
        //Arnold/Gosling
        book = new DefaultMutableTreeNode(new BookInfo
            ("The Java Programming Language", "arnold.html"));
        category.add(book);
        //Chan
        book = new DefaultMutableTreeNode(new BookInfo
            ("The Java Developers Almanac",
             "chan.html"));
        category.add(book);
        category = new DefaultMutableTreeNode("Books for Java Implementers");
        top.add(category);
        //VM
        book = new DefaultMutableTreeNode(new BookInfo
            ("The Java Virtual Machine Specification",
             "vm.html"));
        category.add(book);
        //Language Spec
        book = new DefaultMutableTreeNode(new BookInfo
            ("The Java Language Specification",
             "jls.html"));
        category.add(book);
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
    private static void createAndShowGUI() {
        if (useSystemLookAndFeel) {
            try {
                UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e) {
                System.err.println("Couldn't use system look and feel.");
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);
        //Create and set up the window.
        JFrame frame = new JFrame("TreeDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        TreeDemo newContentPane = new TreeDemo();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}

you can use the method getSelectionPaths() in the class JTree. It will return an array of all the TreePaths you have selected. Then on each of the TreePath you got use the method getLastPathComponent() to get the nodes which you have selected.
Hope this solves your problem.

Similar Messages

  • How can I select multiple photos of files without selecting each individual one

    How can I select multiple files or photos without having to select each individual one? Like you can do on Windows

    Op: without tapping on each one individually
    tap all the photos you want to delete.
    Note what the OP is asking.

  • How can I select multiple photos without tapping on each one individually

    How can I select multiple photos without tapping on each one individually?

    Op: without tapping on each one individually
    tap all the photos you want to delete.
    Note what the OP is asking.

  • How can I select multiple clips in the event browser?

    I can't seem to figure out how to do something that should be pretty simple. I want to select multiple clips in the event browser that aren't next to each other. Right now it's only letting me select the two clips with every other clip in between. Is there a keyboard function that will allow me to deselect the clips in between while leaving the two on the outside selected? In Apple's finder you can do this with files by holding down shift-command while clicking on the ones you want. Or is there away to rearrange clips in the event browswer?
    I'd like to be able to create a multicam clip, but there is always going to be other media in between the clips I want to combine, so how can I select only the clips I want?
    Thanks!

    Holding the Command key should let you select non-contiguous items, just as in the Finder.

  • TS2128 How can I select multiple SEPARATE objects/words in Pages (Mavericks version)?

    When I type a document and decide to italicise a couple of separate words throughout the document how can I select them at once? Pressing Shift selects all the words between the first and the second, that does not help me. In Pages 09 it worked with either cmd or ctrl or alt (I don't remember which, but one of them worked) but I tried all of them now and nothing happens.
    Can anyone help me?
    Thank you!

    You can't do it anymore. Pages 5 is a stripped application and has lost about 90 feature that Pages 09 has. Read more about it in other threads in this forum.

  • How can I select multiple cells in tableview with javafx only by mouse?

    I have an application with a tableview in javafx and i want to select multiple cells only by mouse (something like the selection which exists in excel).I tried with setOnMouseDragged but i cant'n do something because the selection returns only the cell from where the selection started.Can someone help me?

    For mouse drag events to propagate to nodes other than the node in which the drag initiated, you need to activate a "full press-drag-release gesture" by calling startFullDrag(...) on the initial node. (See the Javadocs for MouseEvent and MouseDragEvent for details.) Then you can register for MouseDragEvents on the table cells in order to receive and process those events.
    Here's a simple example: the UI is not supposed to be ideal but it will give you the idea.
    import java.util.Arrays;
    import javafx.application.Application;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.SelectionMode;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.input.MouseDragEvent;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.VBox;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    public class DragSelectionTable extends Application {
        private TableView<Person> table = new TableView<Person>();
        private final ObservableList<Person> data =
            FXCollections.observableArrayList(
                new Person("Jacob", "Smith", "[email protected]"),
                new Person("Isabella", "Johnson", "[email protected]"),
                new Person("Ethan", "Williams", "[email protected]"),
                new Person("Emma", "Jones", "[email protected]"),
                new Person("Michael", "Brown", "[email protected]")
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage stage) {
            Scene scene = new Scene(new Group());
            stage.setTitle("Table View Sample");
            stage.setWidth(450);
            stage.setHeight(500);
            final Label label = new Label("Address Book");
            label.setFont(new Font("Arial", 20));
            table.setEditable(true);
            TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
            firstNameCol.setMinWidth(100);
            firstNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("firstName"));
            TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name");
            lastNameCol.setMinWidth(100);
            lastNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("lastName"));
            TableColumn<Person, String> emailCol = new TableColumn<>("Email");
            emailCol.setMinWidth(200);
            emailCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("email"));
            final Callback<TableColumn<Person, String>, TableCell<Person, String>> cellFactory = new DragSelectionCellFactory();
            firstNameCol.setCellFactory(cellFactory);
            lastNameCol.setCellFactory(cellFactory);
            emailCol.setCellFactory(cellFactory);
            table.setItems(data);
            table.getColumns().addAll(Arrays.asList(firstNameCol, lastNameCol, emailCol));
            table.getSelectionModel().setCellSelectionEnabled(true);
            table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
            final VBox vbox = new VBox();
            vbox.setSpacing(5);
            vbox.setPadding(new Insets(10, 0, 0, 10));
            vbox.getChildren().addAll(label, table);
            ((Group) scene.getRoot()).getChildren().addAll(vbox);
            stage.setScene(scene);
            stage.show();
        public static class DragSelectionCell extends TableCell<Person, String> {
            public DragSelectionCell() {
                setOnDragDetected(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        startFullDrag();
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
                setOnMouseDragEntered(new EventHandler<MouseDragEvent>() {
                    @Override
                    public void handle(MouseDragEvent event) {
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setText(null);
                } else {
                    setText(item);
        public static class DragSelectionCellFactory implements Callback<TableColumn<Person, String>, TableCell<Person, String>> {
            @Override
            public TableCell<Person, String> call(final TableColumn<Person, String> col) {         
                return new DragSelectionCell();
        public static class Person {
            private final SimpleStringProperty firstName;
            private final SimpleStringProperty lastName;
            private final SimpleStringProperty email;
            private Person(String fName, String lName, String email) {
                this.firstName = new SimpleStringProperty(fName);
                this.lastName = new SimpleStringProperty(lName);
                this.email = new SimpleStringProperty(email);
            public String getFirstName() {
                return firstName.get();
            public void setFirstName(String fName) {
                firstName.set(fName);
            public String getLastName() {
                return lastName.get();
            public void setLastName(String fName) {
                lastName.set(fName);
            public String getEmail() {
                return email.get();
            public void setEmail(String fName) {
                email.set(fName);

  • How can i select multiple values form select list

    Hi ,
    I have created few items in a page and all items are Lov items and based on these items stacked charts will display. My requirement is I need to select multiple values form LOV's
    Eg: In Interactive report goto filter and select an item and expression as IN and select multiple items and i need to select multiple values like this.
    Please anybody help me how to get multiple values.
    I have one more doubt Can we have a Print preview option in APEX.
    I have to see print preview for stacked charts. is it possible?
    Regards
    Narender B

    HI ,
    Thank you for valuable information and looks good.but Here our client need to select multiple values.... for eg: Open IR report and click on Actions button --->select filter
    select any column , operator as IN and from expression select multiple items.
    I need to select multiple values in that way so, could you please guide me how can i achieve this.
    Regards
    Narender B

  • How can we select multiple rows in table control for module pool program?

    hi guru's
                 i cannt able to select multiple table control rows for deletion of records please give any code to select rows?
    regrards,
    satheesh.

    On the Table Control attributes there is a "Selectability" option where you choose one of: None, Single, or Multiple.  In your code you then need to pick up which rows have the selection column set to 'X'.

  • How can I select multiple people when filtering media using Photoshop Premier Elements Organizer 11?

    I noticed that in using Photoshop Premier Elements Organizer V10, I was able to select more than a single person when filtering media. For example, I may want to find all of my photos that have me with my cousin, John as well as my friend Norm in them.   With Photoshop Priemier Elements Organizer 11, I can only filter on a single person or filter on a group of individuals.  Using a group does not always match the specific filter that I am looking for.  Was this an oversight in the new version?
    (By the way, this feature is also missing with "Places" as well...  For example, I would like to be able to select Austria, Switzerland, and Germany media when adding an Event for my "Trip to the Alps".  I can only select one country at a time.)
    Any suggestions?  Can we get this feature back?

    Have you opened up the Filter menu, which opens along the top of the Organizer's Media Browser?
    With it, you simply check the filters you want to apply, and the Media Browser will show you all media clips to which those filters applies.

  • How can I select multiple files in the Import grid view in LR4?

    So far the only way I have discovered is to laboriously click the checkbox on each image I want to import. It seems that one should be able to select a range with one click (e.g. holding down Shift and then clicking the last image in the range) or by using a context (right-click) menu. No dice. What gives?

    I think two differeng groups of developers on two different planets designed the Library vs the Import views -- they sure are different!!
    I can answer your question because I had the same question and spent weeks clicking each individually.
    First ignore the checkboxes.  Then use click, ctrl+click, shift+click to select the thumbnails (NOT the Checkboxes, which is why I said to forget them for now!!)
    When you have selected what you want, find one of the selected photos and click its checkbox one way or the other, each click selects or deslects all the "selected" photos.

  • How can I select multiple songs in iTunes without having to hold the Command key while clicking each individual song

    Trying to drag a block of songs from iTunes into TuneUp and I have about 1800 songs to bring in.  TuneUp maxes out at 1000 songs per batch, so I can't use Select All, but I also don't want to Command + Click 800 times to get all of those songs selected. 
    Thanks in advance. 

    Answered my own question.  Select song at the beginning of the list.  Hold down the shift key.  Go to the last song you want in your list.  Click that song.  All songs in between will be highlighted.  Such and idiot. 

  • How can i select multiple images at one go?

    Suppose there a numerous images in a webpage which are lined up in columns in the following manner:
    1.jpg
    2.jpg
    3.jpg
    4.jpg
    5.jpg
    6.jpg
    7.jpg
    8.jpg
    9.jpg
    10.jpg
    n+1.jpg
    Now i simply select the last image that is 10.jpg and all the images above upto 1.jpg are automatically selected or vice versa that is i select 1.jpg and all the images below upto 10.jpg are automatically selected.
    Is there any trick/keyboard shortcut to do that?
    Pressing shift and up/down key takes too much time and is much tedious so is there any better way?

    See if this extension will help you.
    http://www.foxyspider.com/
    https://addons.mozilla.org/en-US/firefox/addon/foxyspider/
    ''Note: it may have quit working in Firefox 31 according to the reviews, so the developer of that extension may need to fix it.''

  • Selecting multiple nodes of a tree through ctrl+shift

    Can i select multiple nodes of a tree through ctrl+shift.
    How??
    Thanx

    Take a look at JTree#getSelectionModel() and TreeSelectionModel#setSelectionMode(int).
    _myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

  • How Do I select Multiple songs to Use with Slideshow?

    I am running Lightroom 4 on an iMac with OS - Lion. Love it!
    I am trying to create a slideshow with music in the background but I cannot seem to select more than 1 song. How can I select multiple songs?
    Thanks
    Adrian

    The slide show feature in Lightroom isn't really very flexible or feature packed.  I suspect the design was to provide professional photographers a quick way to show proofs to clients.  You will have to use other software for what you intend to accomplish.  I'm going to be creating a slide show with about 500 images soon.  My intention is to create the slide show with Lightroom and export as video.  Then I will use Premiere Elements and import the video and lay down the music track.  There are easier ways to do it, I know.  But I don't do this kind of thing very often and don't plan to purchase more software that would make it easier.

  • How can I align multiple titles in Premiere Pro?

    We are working on a video (obviously) and we have a bullet list that we'd like to come up as the speaker is naming off specific items. So far we have created a separate title for each bullet point, so that we can control when the bullets fade in. The issue we're having is that we have to eyeball the alignment right now and it's not always accurate. So i'm looking for some help. How can I select multiple titles in the timeline and right align them - OR - is there a way to have all of these bullet points in one title and still maintain control of when they fade in and out?

    This technique will only work with current versions of PPro - it looks harder to do than it actually is:
    Create the title with all the bullet points, aligned as you wish, in the Title Tool.
    Exit the title tool, the title you just created will appear in your project.
    Click on the title to select it (if it is not already selected) and then go to the menu Edit > Duplicate.
    Repeat the duplication process to make as many copies as number of bullet points you want to transition on.
    Place the first copy of the title where you want the Title to appear in your video.
    Double click on the clip of the title on the timeline to re-open the Title Tool. Delete all the text except the first line.
    Now place the second copy where you want it to appear in the video.
    Double click on it to re-enter the Title Tool, and delete all the text except the first two lines.
    Repeat this process for as many bullet points as you have, delating one fewer bullet point each time. You can add transitions at the cut points between the titles (such as a dissolve) to make the next bullet point appear as you wish.
    If you try to to this using an early version of PPro this will not work as the titles and its copies are linked - so if you change one of the copies, it changes all the other titles. Fortunately this has been fixed in the current version.
    MtD

Maybe you are looking for

  • IPhoto 08 gives spinning ball for 2 minutes at launch.

    iPhoto '08 is having trouble starting up on my iMac. When I click the iPhoto icon in my dock, it bounces once and opens the program. All my photos appear. But before I can do anything, the beachball starts spinning. iPhoto locks up and the ball spins

  • My ipod 5 wont connect to wifi, all the other devices in the house will does not make sense

    Ipod 5 wont conect to wifi in my house when other devices do. does not make sense, went to apple store connected no problem there. Funny thing is it has worked since christmas now all the sudden i have problems, any ideas?

  • How to code the ejbCreate() method without initailizing primary key?

    Hi all, I've just started learning about EJBs, and now am at the stage of learning how to create, deploy and test a CMP Entity Bean. Ran into a problem which I'm hoping someone can help out with. I'm using SQL Server 2000 as my backend database, and

  • How do I remove password from iphone

    How do I remove login password after it has been set up?  I tried to turn password off but the option was grayed out.

  • Opt in to iAds???

    This will sound crazy to most but is there a way to opt back in to the iAds? I was given the opt out link and went there out of curiosity. I'd rather have ads that were based on my interests than random ads show up. If they are gonna show up they mig