JTree drag selection

Hello again,
Can anyone provide some advice on how to implement a drag selection of tree nodes. I don't necassarily need code, just some advice on whats the best practice here. I've been studying how to go about it and my best guess is adding all the mouse listeners to the tree and grabbing coordinate and component width and height info based on mouse released and mouse pressed. Is this the way to do it? Can I use dnd in some way?
Thanks for any help.
Shawn

See if this is of any use http://java.sun.com/products/jfc/tsc/articles/dragndrop/index.html

Similar Messages

  • How Do I Drag Select Multiple Comments or Annotations in Adobe Acrobat Pro 9

    How Do I Drag Select Multiple Comments or Annotations in Adobe Acrobat Pro 9

    Hello Sara,
    Yes, command+click will work to select multiple comments. However, I'm working with some PDFs that have a substantial number of comments and this is taking quite some time to select them all. Additionally, it is tricky to click some of them, and if I mis-click, all the selection work is undone and everything becomes deselected. I'd like to know if there is a simpler way to select many multiple comments, such as a simple drag selection in Adobe Acrobat Pro 9.

  • Is there a "Drag-Select" Method?

    I remember many years ago when Aldus PageMaker was popular. In that program I was able to script and perform a "drag-select" in a specific area of choice.
    Can anyone describe or offer any ideas on how to go about this using Applescript or with Javascript?
    (Ps: I only understand applescript, but lets have fun and discover new ways to do something new and learn at the same time!)
    Thank you everyone...

    This will let you act on all items whose top left fall within a range of coordinates; you could easily modify it to deal with items contained by the ranges:
    tell application "Adobe InDesign CS3"
    tell document 1
    <do something to> (every item of all page items of page 1 where item 1 of its geometric bounds is greater than 72 and item 1 of its geometric bounds is less than 400 and item 2 of its geometric bounds is greater than 72 and item 2 of its geometric bounds is less than 500)
    end tell
    end tell
    Shane Stanley <[email protected]>
    AppleScript Pro Sessions <http://scriptingmatters.com/aspro>

  • Shift+Click And Drag Select

    In demonstration mode I can show how to select a range of
    cells in Excel by dragging with the mouse.
    I can achieve the same outcome by using Shift+Click on the
    start and end cells to select the range, although the viewer would
    not see the Shift key being held down of course.
    I am at a loss to see how to get (and require) a user to do
    the same things in a Trainng or Assessment simulation before being
    able to continue with the next step.
    Can anyone advise please?
    Phil_McC

    Hi again,
    I think I have something that will help you. It's in flash
    though so don't know if you're going to be able to use it.
    Basically it draws a rectangle that follows your mouse and then
    leaves the final rectangle in place if your user hits the target
    area. I must confess to heavily borrowing from the Flash help and
    then tweaking.
    I've just published this as player 7 and tested in Captivate
    2 and it works like a charm.
    This is what you do.
    1 - export the Captivate slide you wish to do the drag select
    on into Flash
    2 - get rid of everything apart from the screen shot of your
    excel. You can add everything else in afterwards.
    3 - put the background on the bottom layer of your stack and
    lock it.
    4 - Create a movie clip for the cell to be dragged out. You
    should be able to draw a rectangle the same size as a cell then F8
    it into a movie clip.
    5 - Create another one that's going to be the target.
    6 - Place these both on the stage in the correct location in
    a layer above your background.
    7 - Copy the code below into the topmost layer (usually
    called actions). You'll need to adjust the start positions and
    final rectangle positions (in the rectangle function and xpos and
    ypos) to what you want.
    8 - test the movie and it works :)
    9 - publish as a player 7 swf.
    10 - Import into the relevant place in Captivate - test and
    play.
    Now the code:
    /*THIS CODE REDRAWS THE RECTANGLE AS THE MOUSE MOVES.
    1 - Creates a function for the final rectangle
    2 - Creates the mouse listener for the drawing
    3 - Draws the rectangle dynamically while mouse pressed
    4 - If drawing ends on the target area then the dynamically
    created rectangle is hidden and the full rectangle is displayed
    5 - If drawing doesn't end on target area, rectangle is
    hidden and the user can try again.
    function rectangle() {
    this.createEmptyMovieClip("rect_mc", 5);
    rect_mc.beginFill(0x333333, 30);
    rect_mc.lineStyle(2, 0x333333, 25);
    rect_mc.moveTo(100, 120); //starting point
    rect_mc.lineTo(400, 120); //top line
    rect_mc.lineTo(400, 120); //right side line
    rect_mc.lineTo(400, 320); //bottom line
    rect_mc.lineTo(100, 320); //left side line.
    rect_mc.endFill();
    var xpos = 100;
    var ypos = 120;
    this.createEmptyMovieClip("new_mc", 5);
    var mouseListener:Object = new Object();
    mouseListener.onMouseDown = function() {
    this.isDrawing = true;
    this.orig_x = xpos;
    this.orig_y = ypos;
    this.curPos_mc = new_mc.createEmptyMovieClip("",
    new_mc.getNextHighestDepth());
    mouseListener.onMouseMove = function() {
    if (this.isDrawing) {
    this.curPos_mc.clear();
    this.curPos_mc.beginFill(0x333333, 30);
    this.curPos_mc.lineStyle(2, 0x333333, 25);
    this.curPos_mc.moveTo(this.orig_x, this.orig_y);
    this.curPos_mc.lineTo(_xmouse, this.orig_y);
    this.curPos_mc.lineTo(_xmouse, _ymouse);
    this.curPos_mc.lineTo(this.orig_x, _ymouse);
    this.curPos_mc.lineTo(this.orig_x, this.orig_y);
    this.curPos_mc.endFill();
    updateAfterEvent();
    mouseListener.onMouseUp = function() {
    this.isDrawing = false;
    this.curPos_mc.hitArea = target_mc;
    if (this.curPos_mc.hitTest(target_mc)) {
    this.curPos_mc._visible = false;
    rectangle();
    } else {
    this.curPos_mc._visible = false;
    Mouse.addListener(mouseListener);
    Let me know if you have any issues or want the .fla or .cp
    file with this.
    Cheers
    JiminiCricket

  • [svn:fx-trunk] 10925: Redo the implementation of dragging & selection being handled upon mouseDown in List .

    Revision: 10925
    Author:   [email protected]
    Date:     2009-10-07 18:52:06 -0700 (Wed, 07 Oct 2009)
    Log Message:
    Redo the implementation of dragging & selection being handled upon mouseDown in List. Evtim will fix up the behavior such that in a multi-select action, mousing down in a selected item will drag the selected set while mousing down in a non-selected item will select that item anew.
    QA: Yes, but don't include in those 3 tests till Evtim checks in, hopefully tomorrow
    Doc: No
    Checkintests: Pass
    Other tests: List tests pass, List D&D tests pass with 3 exclusions.
    Noteworthy for Integration: No
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/DropDownList.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/List.as

  • Drag selection in spark datagrid?

    Is there an easy way to enable a spark DataGrid to use drag selection, similar to how you can select cells in Excel or Google Docs? Or will I need to track mouse movements and manually manipulate the selectedCells?
    Thanks!
    -Aaron

    Couldn't find a built in way to do this, but it turned out to be pretty easy thanks to the GridEvent classes that solve the challenge of know what row/column index the mouse is interacting with. My final solution:
    A class that extends spark::DataGrid
    private var _allowDragSelection:Boolean = false;
    private var dragSelectionAnchor:CellPosition;
    private var dragSelectionStarted:Boolean;
    * If true and selectionMode is GridSelectionMode.MULTIPLE_CELLS the user can drag their
    * mouse to select a rectangular area of cells, just like Excel or Google Docs.
    public function get allowDragSelection():Boolean { return this._allowDragSelection; }
    public function set allowDragSelection(value:Boolean):void {
              if(this._allowDragSelection == value)
                        return;
              this._allowDragSelection = value;
              if(this.allowDragSelection)
                        this.addEventListener(GridEvent.GRID_MOUSE_DOWN, this.handleGridMouseDown);
              else
                        this.removeEventListener(GridEvent.GRID_MOUSE_DOWN, this.handleGridMouseDown);
    private function handleGridMouseDown(e:GridEvent):void {
              if(this.selectionMode != GridSelectionMode.MULTIPLE_CELLS)
                        return;
              this.dragSelectionAnchor = new CellPosition(e.rowIndex, e.columnIndex);
              this.dragSelectionStarted = false;
              this.addEventListener(GridEvent.GRID_MOUSE_DRAG, this.handleGridMouseDrag);
              this.stage.addEventListener(MouseEvent.MOUSE_UP, this.handleDragMouseUp);
    private function handleGridMouseDrag(e:GridEvent):void {
              // don't start processing selection drag until mouse has left the selection anchor
              if(!this.dragSelectionStarted && e.rowIndex == this.dragSelectionAnchor.rowIndex && e.columnIndex == this.dragSelectionAnchor.columnIndex)
                        return;
              // once started, process changes even if the user drags back over the anchor
              this.dragSelectionStarted = true;
              // local to avoid expensive getter cost
              const selectedCells:Vector.<CellPosition> = e.grid.selectedCells;
              // determine the selection rectangle from the anchor to the current cell
              const rowFromIndex:int = Math.min(this.dragSelectionAnchor.rowIndex, e.rowIndex);
              const rowToIndex:int = Math.max(this.dragSelectionAnchor.rowIndex, e.rowIndex);
              const colFromIndex:int = Math.min(this.dragSelectionAnchor.columnIndex, e.columnIndex);
              const colToIndex:int = Math.max(this.dragSelectionAnchor.columnIndex, e.columnIndex);
              // create new cell positions selection vector, and track if any new cell is added
              var cells:Vector.<CellPosition> = new Vector.<CellPosition>();
              var cellsChanged:Boolean = false;
              for(var row:int = rowFromIndex; row <= rowToIndex; row++){
                        for(var col:int = colFromIndex; col <= colToIndex; col++){
                                  var cell:CellPosition = new CellPosition(row, col);
                                  cells.push(cell);
                                  cellsChanged = cellsChanged || !selectedCells.some(function(c:CellPosition, i:int, v:Vector.<CellPosition>):Boolean {
                                            return c.rowIndex == cell.rowIndex && c.columnIndex == cell.columnIndex;
              // assign the new selection only if it changed (Flex is pretty slow here with big selections)
              if(cellsChanged || selectedCells.length != cells.length){
                        this.selectedCells = cells;
                        // maintain the selection anchor for any following SHIFT click selection
                        this.grid.anchorRowIndex = rowFromIndex;
                        this.grid.anchorColumnIndex = colFromIndex;
    private function handleDragMouseUp(e:MouseEvent):void {
              this.removeEventListener(GridEvent.GRID_MOUSE_DRAG, this.handleGridMouseDrag);
              this.stage.removeEventListener(MouseEvent.MOUSE_UP, this.handleDragMouseUp);
    Cheers.
    -Aaron

  • How to disable dragging selected text to web search?

    How to disable dragging selected text to web search?

    Hmm, I haven't heard of that before. It's a new tab page with no relation to what you were dragging?
    I wonder whether this might be a feature of one of your extensions. You can review them, and disable/remove any that are nonessential or unrecognized, here:
    orange Firefox button (or Tools menu) > Add-ons > Extensions category
    If you disable extensions, usually a link will appear above at least one of them to restart Firefox. You can complete your work on the tab and click one of the links as the last step.
    If that makes no difference, you could test in Firefox's Safe Mode -- that's a standard diagnostic tool to bypass interference by extensions (and some custom settings). More info: [[Troubleshoot Firefox issues using Safe Mode]].
    You can restart Firefox in Safe Mode using
    Help > Restart with Add-ons Disabled
    In the dialog, click "Start in Safe Mode" (''not'' Reset)
    Any difference?

  • Drag select and move multiple items

    Hi there,
    I'm currently creating a word game where I would like to place tiles, but if possible I need it to be possible to drag select groups of tiles (preferably with a visible selection box as you drag) and move them around all together.. is there a simple way to implement this and still have the tiles snap to a grid ?
    Many Thanks in advance
    Martin

    you can reparent your selected group to a new parent and drag the parent.

  • Drag Select Inside Points With The Direct Selection Tool While Above An Object?

    I'm trying to modify a path in InDesign CS5 (Fig. 2), as it is now I have to select each point individually. Becasue while you're zoomed in (Fig. 1), you can't drag and select the points. When you attempt to do that, you end up dragging the whole image.
    Is there a way to drag select inside points with the direct selection tool while your directly above the image with the paths you want to select?
    Fig. 1
    Fig. 2

    FAIL #1:
    No. When you copy paste the Cliiping Path [NOT the frame] into Illustrator, then alter the path and paste back into Indesign, it pastes it back as a FRAME, NOT a CLIPPING PATH.
    FAIL #2:
    Why do people comment on this stuff without first testing what they are suggesting?
    What you suggested doesn't work or even make sense.
    Apprently in InDesign, you can't have a CLIPPING PATH without an IMAGE there to begin with. When a FRAME OBJECT contains an IMAGE the option to convert the object to an UNNASSIGNED OBJECT is greyed-out, as in UNSELECTABLE, as in NOT POSSIBLE, which is another way of saying IMPOSSIBLE, which in most circles pertains to MAJOR FAILAGE.
    When you CUT [hold command then press X] the CLIPPING PATH, from the FRAME/OBJECT you can then unassign the object, but when you paste the CLIPPING PATH back in, it invariably pastes the IMAGE along with the CLIPPING PATH, and once again the UNASSIGNED OBJECT is simply an ordinary frame with an image, and thus NO LONGER AN UNASSIGNED FRAME.
    People like you make life harder dude, seriously.
    Again, like some of the folks above, you're confusing a FRAME PATH [that you can alter and create with the pen tool as well] with a CLIPPING PATH. They are NOT the same thing. 
    Know the difference between the two before you feel inclined to respond.
    My kingdom for someone out there with some merit and sense of accountability.
    It's like, where do you people work? Are you serious? SMH.

  • Tap to drag select by whole words using the Trackpad!

    I figured out that there is an easy way to drag select by whole words using the Trackpad... just put your mouse over the word you want to start the selection from and ...
    tap, pause, tap, tap
    ... or another way to say it might be ...
    tap, double tap
    I find this method almost 100% reliable, it's effortless to get the timing right.
    Being able to do this now removes the only thing that I've missed about a mouse since switching to the trackpad.
    Yay!

    On the trackpad, after double tapping to select a word, you cannot drag to continue selecting more words. And if you triple tap, it selects the entire paragraph. If you double tap to select a word, pause and tap-drag, the selection doesn't change with your dragging. If you double tap to select a word, pause, and double-tap-drag, it starts a drag/drop operation using the original selection.
    The method I described allows you to accomplish with a trackpad, the operation that mouse users take for granted - double click/drag to select a word and drag to select more words.
    As far as I know, the technique I posted at the top is not widely known. At least I didn't turn up anything with my google searching and have used this trackpad for almost a year without knowing about this trick.
    FYI - my trackpad "Point & Click" settings are:
    tap to click
    secondary click is tap with two fingers
    3 finger drag disabled

  • Drag Selection Area implementation

    Hello,
    I'm trying to implement a "drag selection area"
    functionality, like a clipping style. Where user will draw a
    rectangle on top of a series of sprites, and that will perform an
    action to those sprited whitin the rectangle.
    I was wondering how it would be best to implment it? In
    terms of performance.
    I was thinking of using the .containsPoint() of the
    Rectangle, however, that means I have to do lots os calculations as
    my sprites are lines drawn all over the screen. So, calculating the
    intersection points for all lines would not be good...
    Is there a way to get the sprites or elements that are drawn
    "behind" the rectangle? since this lines are sprites and they are
    drawn before the rectangle I thought that will be a better way of
    getting the "selected" items?
    Marcela

    You may want to use openGL calls instead of
    java.awt.Graphics otherwise you would lose hardware
    acceleration for drawing the box. These calls would
    be made within gl4java's GLAnimCanvas display()
    method. Basically, if your GLAnimCanvas implements
    MouseListener and MouseMotionListener you can change
    the box coordinates within the appropriate method
    (e.g. mouseDragged, mousePressed) and have the box
    rendering code within display()Not necessarily. Java2D is accelerated in version 1.4

  • Multiple Selection in JTree, Drag & Drop

    Hi everybody,
    I was wondering if anyone knows how to implement Multiple Selection Drag and Drop in a JTree. I know that there used to be a bug in jdk 1.3 that would allow it, but I suspect 1.4 fixed that. I've implemented Single-selection just fine, but I'm trying do Multiple selection by drawing a selection rectangle and selecting whatever nodes are contained within that rectangle. So far I've implemented it by adding a MouseListener to my JTree, finding which rows are intersected by the rectangle and calling addSelectionRow() to add the TreePaths.
    Is there an easier way to multiple selection now that the bug of 1.3(I hope) has been fixed?

    Okay, now I've implemented the changes in the DragGestureListener, DragSourceListener and DragTargetListener in order to make Multiple Selection possible, however I want to select multiple items the same way Windows Explorer does by:
    1. pressing the left-mouse button & dragging a "selection" rectangle which selects all the nodes contained within that rectangle.
    2. then drag and drop is accomplished by pressing one of the selected nodes and dragging it (along with it's other selected siblings) to the destination.
    In order to accomplish this I added into the Constructor of my JTree extending class this code:
    public class MyTree extends JTree {
    private static int x1, y1, x2, y2;
    public MyTree(DefaultMutableTreeNode rootNode){
    // Other Constructor stuff...
    this.addMouseMotionListener( new MouseMotionListener() {
    public void mouseDragged(MouseEvent e) {  
    x2 = e.getX();
    y2 = e.getY();
    repaint();
    public void mouseMoved(MouseEvent e){     }
    this.addMouseListener(new MouseAdapter(){
    boolean dontRelease = false;
    public void mousePressed( MouseEvent e){
    x1 = e.getX();
    y1 = e.getY();
    int[] rows = getSelectionRows();
    boolean dropSel = true;
    if (rows != null){
    for (int i = 0; i < rows.length; i++){
    Rectangle rect3 = getRowBounds(i);
    if (rect3.contains(x1, y1)){
    dropSel = false;
    dontRelease = true;
    if (dropSel){
    for (int i =0; i < rows.length; i++)
    removeSelectionRow(i);
    public void mouseReleased( MouseEvent e){
    x2 = e.getX();
    y2 = e.getY();
    repaint();
    if (dontRelease == false) {
    Rectangle rect2 = new Rectangle(Math.min(x1, x2),
    Math.min(y1, y2), Math.abs(x1-x2), Math.abs(y1-y2));
    int rowCount = getRowCount();
    for (int i = 1; i < rowCount; i++) {
    Rectangle rect3 = getRowBounds(i);
    if ((rect2.contains(rect3)) || (rect2.intersects(rect3))){
    addSelectionRow(i);
    dontRelease = false;
    repaint();
    The idea was that for every press of the mouse the 1st set of x,y coords. are taken to be the starting corner of the "selection" rectangle, and every point passed over while dragging would be the ending corner of the rectangle (so that in paintComponents, you could actually draw the rectangle).
    Once the mouse is released it will check to see if the selection rectangle had contained or intersected any of the rows (basically I find how many rows are being shown in the tree and go through each one to see if there is intersection/containment). If a row is contained it becomes selected.
    The remaining code in MousePressed is used if node(s) were previously selected it goes through and checks to see if this mouse press is at the location of one of the previous selected nodes - if it is then you can drag that node along with all of its siblings to their destination. However if your mouse press is not on one of the selected nodes - all the nodes should be deselected (like in explorer if you press away from your selection, you lose it). If you select and begin to drag your selection dontRelease should not allow the creation of another "selection" rectangle to occur during the drag-n-drop process.
    -That's how I thought this code should work. Unfortunately as it does most of these things it does not correctly implement rule #2 of Windows Explorer (2. only by dragging one of the selected nodes can you drag them, otherwise you lose them)...currently as long as something is selected you can do a mouse press and drag from another location and as long as that location does not contain a node (like it is a blank area in the JTree), you can drag everything to the destination from when you start dragging.
    I looked around and saw that perhaps it is due to the BasicTreeUI interferring with it's own MouseInputHandler() so I wrote MyTreeUI that extends BasicTreeUI, basically changing only the MouseInputHandler to contain the functions above, and I blocked /**/ those functions from my MyTree Constructor.
    Then in my main class (the one of instantiate my MyTree and my DefaultMutableTreeNodes), I wrote:
    try
    String myTreeUI = "MyTreeUI";
    UIManager.put( "MyTreeUI", myTreeUI );
    UIManager.put( myTreeUI,
    Class.forName( myTreeUI ) );
    } catch( ClassNotFoundException cnfe ) {
    System.err.println( "My Tree UI class not found" );
    System.err.println( cnfe );
    ...thinking that that would be all I needed in order to set MyTreeUI as the JTree's UI, LooknFeel, etc. and although I did not get that ClassNotFoundException when running the program, it did not have any of the functionality that I had written ( I even wrote a System.out.println() in my MousePressed() function in MyTreeUI so that it would let me know that it is working and it never appeared). It was as if the MyTreeUI was not loaded or attached to the JTree. I also called:
    System.out.println("this is UI: " + jTree1.getUIClassID() );
    to see which UI my MyTree instantiate was using and it would printout TreeUI, not MyTreeUI. So I'm wondering what it is I'm doing wrong, I think I am very close to having this thing working but I want to know if anybody here would be able to let me know what I'm doing wrong or what would be the best way to go about implementing this Windows Explorer Multiple Selection JTree.
    Sorry for the long-winded explanation,
    -Meddev24.

  • JTree Drag and Drop (Multi Nodes)

    Hi All!
    I have been searching the forums for a few hours over the last few days and have found some nice examples and explanations on how to implement drag and drop for a jtree.
    However, I would love to know how this is accomplished when selecting multiple nodes.
    I want to be able to see all the selected nodes being dragged...
    Anyone implemented anything of the sort... or even just knows how to do this?
    Thanks in advance!!
    Aaron.

    When you drag get the [x,y] mouse position and use the JTree method:
    getRowForLocation(x, y) for node you at the also for the parent node location of the child node.
    Once the childY is less than childParentY, you stop the drag.
    Hope that helps?

  • Command-Drag select in list view in Lion

    There are many things about Lion that irk the crap outta me, but this one is near the top. In ALL previous versions of Finder, one could, in list view, select a bunch of files by dragging over them, then, holding the command key down, add more non-contiguous files to the selection, again by dragging. If you try that in Lion, it starts dragging the whole lot of what you just selected to, usually, the root folder of the window you have open.
    It appears that the only way to add extra non-contiguous files to a selection is to individually click each one of them. Really? Really? Who decided this?
    So IS there a way to do as i ask? And no, don't tell me to use another view, that's not helping.
    Thanks
    Adam

    Try it. I dare you.
    Okay, smarty-pants:
    http://web.me.com/thomasareed/test.mov
    If you want further assistance, I'd advise changing the attitude.

  • Photoshop Elements 11 - drag selection from photo to photo in bar below does not work

    Hi,
    When opening a photo it appears in a bar below, when opening a second one, I could make a selection with the Lasso - Selection Tool and drag this to the first picture below in the bar. Thereafter the FIRST picture would automatically pop up WITH the selection on it from the second.
    For some reason I can not drag it any more to the picture below, It is like it does not accept it or like the first picture does not respond to the action?
    Help would be appreciated since I don't know how to continue working with it.
    Kind regards,
    Leen

    Please post Photoshop Elements related queries over at
    http://forums.adobe.com/community/photoshop_elements

Maybe you are looking for

  • QM-WM customization step by step

    Dear all, It will be highly appreciated if anybody send step by step QM-WM customization and master data set up for different type of scenario in WM. I need it for implementation purpose. Thanks in advance.

  • Centigon map in dashboard

    Hi, I have created a dashboard in which Centigon maps is embedded. The map works completely fine when dashboard is opened in local machine. But when the dashboard is deployed in dev server, the map does not work at all when dashboard is opened throug

  • Safari keeps closing web pages, quitting on new iPad Air?

    Any ideas?

  • Is the unlocked 5s available in Houston Tx.?

    Hi I would be travelling to Houston in a day or two. I need to pick up the Iphone 5s in gold unlocked version.  Is it available? Thanks

  • Can't find client class

    Hi, I have been testing with a J2EE turtorial. I have created a cliet file jaxrpc-simpleClient.jar. When I try to run it using : appclient -client ../jaxrpc-simpleClient.jar I get the error: 2005-aug-10 22:00:07 com.sun.enterprise.appclient.Main <ini