Limit JTable selection behavior

I have a simple table with 3 columns an multiple rows. If I select a row with the left mouse button and, with out letting go, move the mouse pointer up to a higher row or down to a lower row the currently selected row changes to the row the mouse pointer is over.
I need to stop this behavior.
If I select a row with a left mouse press and move the mouse around when I do a mouse release I want the selected row to still be the one i did the mouse pressed action over.
Please Help.

This change seemed to work for me
          table = new JTable(data, names){
               int prevRow = -1;
               //override the default selection behavior
               public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                    if(ctrlDown){
                         //ctrl + dragging should add the dragged interval to the selection
                         if ( rowIndex != prevRow ) {
                              prevRow = rowIndex;
                              super.changeSelection(rowIndex, columnIndex, true, false);
                    else{
                         //clicking adds a row to the selection without clearing others
                         //dragging without holding ctrl clears the selection
                         //and starts a new selection at the dragged interval
                         super.changeSelection(rowIndex, columnIndex, !extend, extend);
          };

Similar Messages

  • Overriding Default JTable Selection Behavior

    I'm attempting to override the default selection behavior of a JTable. For clicking, I want the table to behave basically as if the ctrl key was being held down all the time. That works great.
    I want the behavior of dragging a selection to behave a certain way as well. If ctrl is not held down, then a drag should cancel the current selection and start a new one at the drag interval. This works fine too.
    However, if ctrl is held down during a drag, I want the dragged interval to be added to the selection instead of replacing it. This almost works. However, if I hold ctrl while dragging, it no longer let's me "undrag" the selection: once a cell is inside the dragged interval, it's selected, even if you drag back over it to deselect it.
    I understand why that's happening given my approach, but I'm looking for a way around it. Does anybody have any ideas about how to get a JTable to behave the way I want?
    Here's a compilable program that demonstrates what I'm doing:
    import javax.swing.*;
    import java.awt.event.*;
    public class TestTableSelection{
         boolean ctrlDown = false;
         JTable table;
         public TestTableSelection(){
              JFrame frame = new JFrame("Test Table Selection");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //give the table random data
              String [][] data = new String [10][5];
              String [] names = new String [5];
              for(int i = 0; i < 5; i++){
                   names[i] = "C: " + i;
                   for(int j = 0; j < 10; j++){
                        data[j] = "t: " + (int)(Math.random()*100);
              table = new JTable(data, names){
                   //override the default selection behavior
                   public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                        if(ctrlDown){
                             //ctrl + dragging should add the dragged interval to the selection
                             super.changeSelection(rowIndex, columnIndex, toggle, extend);     
                        else{
                             //clicking adds a row to the selection without clearing others
                             //dragging without holding ctrl clears the selection
                             //and starts a new selection at the dragged interval
                             super.changeSelection(rowIndex, columnIndex, !extend, extend);
              //keep track of when ctrl is held down
              table.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent e) {
                        ctrlDown = e.isControlDown();
                   public void keyReleased(KeyEvent e){
                        ctrlDown = e.isControlDown();
              frame.getContentPane().add(new JScrollPane(table));
              frame.setSize(250, 250);
              frame.setVisible(true);
         public static void main(String[] args){
              new TestTableSelection();
    Let me know if any of that isn't clear.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    This change seemed to work for me
              table = new JTable(data, names){
                   int prevRow = -1;
                   //override the default selection behavior
                   public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                        if(ctrlDown){
                             //ctrl + dragging should add the dragged interval to the selection
                             if ( rowIndex != prevRow ) {
                                  prevRow = rowIndex;
                                  super.changeSelection(rowIndex, columnIndex, true, false);
                        else{
                             //clicking adds a row to the selection without clearing others
                             //dragging without holding ctrl clears the selection
                             //and starts a new selection at the dragged interval
                             super.changeSelection(rowIndex, columnIndex, !extend, extend);
              };

  • "resolving alias to" message using aliases on 10.6.8 plus slow text-selection behavior

    Recently after no particular change to my Mac Pro3,2 running 10.6.8 other than some routine software updates, whenever I open an alias on my desktop to standard folders or files, a message shows up "Resolving alias to" whatever the alias name and there's a 2-3 second delay before the folder/file opens. I've found discussion of this issue in some archived discussions but never found a comfirmed solution described, so I'm raising this again. As in others' encounter with this behavior, the slow opening of aliases happens (1) only in my own user account, not in a guest account I set up for test purposes [I have no other user accounts than these], and (2) only happens the FIRST time I open an alias. Subsequent uses of the alias work normally.
    Another strange but possibly related behavior that began at the same time as this alias delay is harder to describe but involves a problem when selecting text using mouse clicks or even highlighting with the mouse for editing. For example, to edit the name of a file or folder on my desktop, I would normally click on the file/folder name, pause a moment and click again: this puts me in edit mode with the current file/folder name highlighted/selected. Now when I attempt this procedure, the second time I click immediately opens the file/folder, as though I had double-clicked rather than clicked+paused+clicked. The only way I can select the name of the file/folder to edit it is to click+long pause (like 3 seconds)+click. Then the text is selected as desired. It's as though the clicks are being recognized (by whatever in the OS recognizes clicks) as much faster than actually made.  There is a similar problem in any program I use that permits text editing, whether Word (Office 2011 for Mac), TextEdit, etc. I have to consciously slow down my cursor/click behavior when selecting text. If not, my actions are misinterpreted as double clicks. This text selection behavior also disappears when using a "Guest" user account, only appearing in my own user account. I Using a different mouse has no effect.
    Steps taken so far. I've Repaired Disk Permissions and Verified Disk using Disk Utility, have Safe Booted, and have turned off all login items in my user account,and recently installed the 10.6.8 supplemental update, all to no avail. Any suggestions or has anyone had and solved this/these problems?

    I think my problem has been that in Sytem Preferences>Mouse, my "Double-Click Speed" was set to the SLOWEST setting. After some experimentation, I now have the that setting two notches from the "Fast" end of the scale. In case it's important, the "Primary mouse button" in my Preferences is set to "Left".
    This not only solves the text selection issues described, but also seems to eliminate the strange "resolving alias to" problem.
    [For the curious, I have a Logitech Performance MX wireless mouse which can be configured with "Logitech Control Center". But the LCC software doesn't control double-click speed; this setting can only be made in the Mouse System Preference pane.]

  • How do you turn off the auto select behavior when working with shape layers?

    How do you turn off the auto select behavior when working with shape layers?
    I am using either of the path selection tools to select only some of the paths on the layer. I have the proper layer targeted. I have the selection too auto select option turned off.
    If another layer has a path in that area, that layer becomes auto targeted and I get the wrong path. Turning off the layer is the only way to avoid this but then I have to  turn on the layer back on between making my selection and transforming to use the other layer as guide. Is there any way to stop this auto select? Locking the other layer does not stop the auto select, just prevents editing.

    As far as i know the move tool options don't have any effect on the path selection tools.
    You might try clicking on one of the path points or on the path itself with one of path selection tools and if you want to select multiple points
    you can shift click with the Direct Selection Tool or Alt click to select the entire path.
    more path shortcuts:
    http://help.adobe.com/en_US/photoshop/cs/using/WSDA7A5830-33A2-4fde-AD86-AD9873DF9FB7a.htm l
    http://help.adobe.com/en_US/photoshop/cs/using/WSfd1234e1c4b69f30ea53e41001031ab64-7391a.h tml

  • Logical limit on Select clause

    I am working on Oracle 10g 10.2.0.3 and I cannot select more than 1000 columns using SQL.
    But I could select more than 1000 columns in Oracle 11g R2.
    What is the limit on number of columns that can be selected in a select query on Oracle 11g R2?
    Also, can i get Oracle documentation which specifies this limit for select query?
    Edited by: 844063 on Apr 26, 2011 10:53 PM

    Well, then, on a related note, I have at least some tables that do not show all the columns in the column or data views in SQL Developer. I get the first 76 columns for one table that I have in mind. The index build utility also does not show all the available columns in the table.
    "Select *" does show all the columns, and so does the DESCRIBE statement. Is there a setting in preferences (I couldn't find it) that controls this?

  • Limit on Select clause

    I am working on Oracle 10g 10.2.0.3 and I cannot select more than 1000 columns using SQL.
    But I could select more than 1000 columns in Oracle 11g R2.
    What is the limit on number of columns that can be selected in a select query on Oracle 11g R2?
    Also, can i get Oracle documentation which specifies this limit for select query?

    Hi,
    I think you can select as many columns you like in both 10g and 11g.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17110/limits003.htm#i288032
    You cannot however use more than 1000 columns in say create view as ... or create table as ...
    In both cases you will get
    ORA-01792: maximum number of columns in a table or view is 1000
    These limits probably also mean that you cannot use more than 1000 columns in your select list, when this is part of subquery factoring or inline views, or whenever the optimizer feels like treating that query as a view or table.
    In other words, you can:
    select 'n1', 'n2', ..., 'n1001' from dual;But you cannot:
    select * from
    select 'n1', 'n2', ..., 'n1001' from dual
    );My guess is, since you have a query in 11g that will not execute in 10g, it is due to how the optimizer re-writes the query in those two versions.
    Regards
    Peter

  • Limit a select statement

    hey everyone
    i was wondering if someone could assist me and tell me how to limit a select statement to just the top 25 outputs. ie: the top 25 employees with the longest years of service.
    any help, i am just learning this stuff
    thanks
    josh

    Assuming the structure of the emp table in the scott schema, something like
    SELECT *
      FROM (SELECT *
              FROM emp
             ORDER BY hiredate desc)
    WHERE rownum < 25Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Cross-JTable selection

    In a scenario where there are two JTable's in order to implement "locked (frozen) columns", one has to address the cross-JTable selection issue that occurs when both tables' "columnSelection" and "rowSelection" properties are enabled, and the user clicks & drags the mouse to select a range of cells across the two JTables.
    Has anyone ever done this?
    Mert

    Interesting question - I would try to register one mouseListener to both tables that makes sure the events are redispatched if the mouse exits the one and enters the other during a addSelection.Or you can try to patch the BasicTableUI.MouseHandler to go on with addSelection even after a mouseExited during a mouseDragged. Never tried it, though. (Always assuming that one there is one selectionListener that extends a selection in one table to the other)
    Greetings
    Jeanette

  • Disabling List View selection behavior

    Hi,
    I am using List view to display some text rows. I need the scroll bar on the right and the Sort option on top of the list but I would like to disable the selection behavior of each row. I am just using the rows for display purpose but the availability of hand-mouse pointer on each row is misleading as it lets the user to think that some action would be available if they click the mouse on a particular row. So I want to take this hand pointer off. Is there any other alternative to provide display of a table of items with a scroll bar or disable this behavior of List View ? Please help.
    Thanks,
    Veena.

    Hi Veena,
    I guess you are using Xcelsius4.5, right? (Because in X5 there is no hand-mouse point.)
    If you are using X4.5, As I know, hand-mouse point couldn't be disabled and there is no scroll bar for table component. But there maybe a walk-around for list view component:
    1.Set the color of "Mouse Over Text" and "Selected Text" to black or other same color;
    2.Set the color of "Selected Fill" and "Mouse Over Fill" to white.
    Then when mouse over a row or select a row, there will be no color effects.
    If you are using X5, you can set Table's scroll bar property in Behavior tab.
    Best regards

  • Modifying JList selection behavior

    What I want to do is change the selection behavior so that if the user clicks on the left half of the cell, the item is selected, but if the user clicks on the right half, the item is not selected. I already have the code to determine where the user clicked, but can't get the selection to not occur when I determine that the user clicked in the "non-selection area" right half.

    After overriding...
    public void setSelectedIndices(int[] indices)
    public void setSelectedValue(Object anObject, boolean shouldScroll)
    public void setSelectionInterval(int anchor, int lead)
    public void setSelectedIndex(int index)...it worked. I implemented each of these like this.
    public void methodX()
      if( clickOnSelectableRegion )
        super.methodX();
      clickOnSelectableRegion = true;
    }It is the responsibility of an outside MouseListener to determine if the click falls on a selectable region or not. If a click occurs that is not on a selectable region, the listener should call setOnSelectableRegion(false) on the List. I set the value back to true so the listener only has to notify the list of "ignorable" clicks.

  • Limit choice selection?

    Hi! I'm having a problem with the option above. When I save my form as pdf file and open it with adobe reader limit choice doesn't work, I can tick as many answers as I want, even though I made 2 answers as maximum. What am I doing wrong?

    Hi Perry,
    I'm work with the Multiple Choice Field. From field properties I tick Limit Choice Selection and I set min 1 max 2 (or 3, doesn't matter).
    On my pc where I have FormsCentral installed I use Adobe reader X, on my laptop I have Adobe reader XI. Nowhere answer limitation works.

  • Any way to limit POV selections between different dimension?

    Hi,
    For Hyperion Planning:
    My users continuously ask for to limit POV selections between different dimensions.
    For example,
    Dimension Entity: West, South, East, North
    Dimension StoreType: Mega, Super, Normal
    However, the following combinations make sense in current business context.
    West - Mega
    West - Super
    West - Normal
    South - Normal
    East - Normal
    If users select East - Mega, this does not make sense since there is no such combinations in current business context.
    Do any one know a way to limit the wrong selection?
    Thank you in advance.
    Casper H

    This link will give you the answer :- Re: Help in Data forms
    probably not the answer you want to hear though.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • CAT2 - Limit WBS selection list

    Hi,
    We are running Timesheets using CAT2.
    I am trying to limit the selection of projects (receiver WBS element) via the search help screen so that only released (REL) projects are listed. Can this be achieved in config or will this need to be coded?
    Currently, every WBS created in CJ20N is visible, no matter what the system status is: CRTD, REL, TECO, CLSD - even marked for deletion. It is only when I physically delete a WBS  that it disappears from the list.
    Obviously these codes will error on the timesheet if specific statuses have been set, so how can I prevent the users seeing them on the selection list if they are not for use?
    Any help/advise would be useful.
    Thanks in advance.

    Hi graeme,
    1. One way is using search help exit,
       and restrict the values.
    2. Another is using EXIT,
      and checking, if there is any wrong entry  in the time sheet.
    3. For that use the enhancement CATS0006 (using smod tcode).
      There u can validate the entire time sheet,
      while saving.
      (if there is any error , u can restrict from saving,
      after giving some message)
    regards,
    amit m.

  • Selecting Behavior property of the Call Behavior Action on a UML Activity Diagram

    I have 16 projects in my UML solution, and I need to be able to select a Behavior in the Call Behavior Action property that is in one Activity Diagram, from a list of Activity Diagrams that are located in different projects, but still in the same overall
    Solution.  Currently, it looks like I can only select Behaviors from within the same project.

    This is related to TFS.  I am using Visual Studio 2013, Ultimate.
    It would be more meaningful if I could insert an Activity Diagram into another Activity Diagram, which is similar to what I can do with an Activity Diagram into a Use Case Diagram.  However, TFS will not allow that.  Instead there is the option
    of using the Call Behavior Action.  When I use this item from my toolbox, I can open the Properties for it and select from a list of "Behaviors" (i.e. Activity Diagrams) that are located in the same Project.  I want to select an Activity
    Diagram from a different Project, but still within the same Solution.  Here is a picture:
    These diagrams are all within the same project.  I want to be able to select a diagram from a different project within the same Solution.  For example, select a diagram from Cash Management as the "Behavior" for an item in the Dealer
    License Project.  They are both in the same Solution, so it seems like I should be able to do that.
    Thanks for any advice.
    Jeff
    Jeff

  • JTable multiple interval selection behavior

    How do you force a JTable to behave as if the control key is always pressed, without the user actually holding down the control key?
    My desired result is to have the user be able to select multiple independent intervals, exactly like the behavior when the ctrl key is held down. But I do not want the selection cleared like when the ctrl key is released and a new interval is selected.

    I solved my problem by subclassing JTable to invert the toggle parameter sent by BasicTableUI.java in the event that control is depressed while making a selection.
    Now instead of using javax.swing.JTable I will use my Toggle inverted version below.
    import javax.swing.JTable;
    public class JTableToggle extends javax.swing.JTable {
        public JTableToggle(){
            super();
        public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
            // toggle is true in the case where the control key is pressed, i will invert that case.
            toggle = !toggle;
            super.changeSelection(rowIndex,columnIndex,toggle,extend);
    }

Maybe you are looking for

  • Single invoice for Multiple Purchase Orders

    Hi, How to Park the single invoice for multiple purchase orders

  • First problem since 2009 - Yosemite

    Problem description: I have a fairly old macbook pro, purchased in 2009.  Never had any problems with it but since upgrading to yosemite it takes minutes to boot up, before the download it was seconds.  Also the spinning ball of death shows up at lea

  • Oracle 11.2 in Solaris 10 non-global zone?

    When I try to install in a non-global zone in Solaris 10, the installer system check fails; I think this problem is well-known, but I can't find the guidance notes any more. The generic documentation isn't much help, I'm afraid. This is what I get fr

  • Migrating access 2003

    Hello, This access 2003 schema is not properly normalized and has some design inconsistencies. What's the recommended approach to migrate to Oracle? Migrate to Oracle 9i and fix the issues OR Fix access tables, forms (and code), reports (and any code

  • Custom transactions execution from base on conifguration table entry.

    Hello, I have a reqiurement where I name of the custom Transaction programs are maintained in a configuration table. I am creating a custom report on whose execution, the selection screen should show the name name of all those transaction proigrams i