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);
}

Similar Messages

  • JTable - how to do multiple interval selections

    Suppose if i have a 10 rows in the table.
    By Default, How can i select multiple interval rows selection.
    Like 2,5,7,8,10 rows has to be selected.
    After loading i should be able to select different rows also.
    How can I do it.

    You can do that by using ListSelectionModel from the JTable by calling getSelectionModel()
    Detail of the selection model can be found inside Java API

  • JList with Multiple interval Selection

    I am trying to get all the selections that I selected when
    a button is pressed. I just don't under how it works when the selection is not contiguous. if it was I just need the first and last selected but I don't know what to do with this situtation
    Duke dollars avaiable

    If your JList allows multiple sections then this:
    1.select first item
    2. hold sown the shift key
    3. select Nth item
    will select all the items between the first and the Nth.
    Holding down the Ctrl key will select individual items.
    To make your JList accept multiple selections you use setSelectionMode

  • 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);
              };

  • 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);
              };

  • Multiple keystrokes selection for a JComboBox in JTable

    Has anyone used multiple keystrokes selection in a JComboBox inside JTable before? I can get it done outside JTable by using: http://javaalmanac.com/egs/javax.swing/combobox_CbMultiKey.html
    Looks like JTable has all kinds of problems to support JComboBox.
    Suggestions?
    Thanks,
    James

    If I read you right, you want to use a multiple keystroke combo box as an editor in a JTable?
    If you create the JComboBox as you would like it and then install it as an editor in the column(s) JTable the editor will work like the JComboBox
    Example:
    //- you would have that keyselection Manager class
    // This key selection manager will handle selections based on multiple keys.
    class MyKeySelectionManager implements JComboBox.KeySelectionManager {    ....    };
    //- Create the JComboBox with the multiple keystroke ability
    //- Create a read-only combobox
    String[] items = {"Ant", "Ape", "Bat", "Boa", "Cat", "Cow"};
    JComboBox cboBox = new JComboBox(items);
    // Install the custom key selection manager
    cboBox.setKeySelectionManager(new MyKeySelectionManager());
    //- combo box editor for the JTable
    DefaultCellEditor cboBoxCellEditor = new DefaultCellEditor(cboBox);
    //- set the editor to the specified COlumn in the JTable - for example the first column (0)
    tcm.getColumn(0).setCellEditor(cboBoxCellEditor); Finally, it may be necessary to to put a KeyPressed listener for the Tab key, and if you enter the column that has the JComboBox:
    1) start the editting
    table.editCellAt(row, col);2) get the editor component and cast it into a JComboBox (in this case)
    Component comp = table.getEditorComponent();
    JComboBox cboComp = (JComboBox) comp;3) give this compent the foucus to do its deed     
    cboComp.requestFocus();Hope this helps!
    dd

  • Disabling multiple row selection in JTable

    hi,
    I have a JTable and I want to disable the multiple row selection.
    I used
    getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);and this working fine with ctr+clicking on a row
    but if i am using shift key instead of Ctrl key multiple selection is possible....
    Any idea y?and how to resolve it??
    thnx
    ~neel

    Use table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);I don't know if it differs but I use it and I don't have the problems you describe. Might be a bug in your Java version?!
    Message was edited by:
    pholthuizen

  • How to set a payload field value only once for multiple instances selected?

    The user needs to set a payload field value and then he can approve the task so the task can continue through the process, that's fine when the user selects one instance and sets the value in the task details section and then clicks the approve button, but how do we achieve the same behavior in a multiple way?, I mean the user can select multiple tasks in the workspace (in this case the details task page is not available and instead the following label appear "Multiple tasks selected") then if the user clicks the Actions drop down -> APPROVE he only gets the message "your request was processed successfully", so how can the user modify the payload field value only once for all the selected tasks so when he clicks APPROVE the value is populated in all the instances selected.
    Thanks,
    Carlos.

    In the action which displays the edit page just set the form idx value before displaying the jsp.

  • 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

  • Fixed time interval selection in Infopackage

    Hi Guys,
    I have a generic data source from PA0315 table that I am using to supply master data 0EMPLOYEE. In the update tab of the infopackage it has a fixed time interval selection with Start Date and End Date. I enter 01.01.1900 to 31.12.9999 so that I can capture the entire data for every load.
    But when ever I enter that selection option it always returns with '0' data. But if I enter specific date ranges it returns with data. But being specific does not help me b/c I want the entire date range.
    Has anybody come across this before and have an idea on a solution to capture all the data.
    Any response will be appreciated.
    K.

    Hi,
    I'm facing a similar problem. I would really appreciate if anyone can help in this regard.
    We have a table in R/3 which has time-dependent data. For example, for a single OBJID we could have multiple records with different BEGDA/ENDDA. When we try to load this data into BW InfoObject, we see a time-dependent data selection in update tab of infopackage. We need to select BEGDA/ENDDA since otherwise during loads we would get a "DUPLICATE RECORDS" load error in BW.
    The problem is when we enter a Fixed-time interval Start Data and End Date in the InfoPackage, only the records with that StartDate and EndDate are loaded. Ideally I would want to see all the records whose BEGDA/ENDDA falls in the range of StartDate and EndDate.
    I tried modifying the ROOSFIELD table for the data source. I made the BEGDA SELOPTS as GE(16) and ENNDA SELOPTS as LE(64). But still it doesn't seem to work. I tried the same in RSA3. Unless we give a range for BEGDA it doesn't seem to behave as expected. Could someone let me know how I can load all records to BW whose BEGDA/ENDDA fall in the range of StarteDate and EndDate.
    Thanks,
    Anil

  • "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.]

  • The file size of selected file in input file control is shown as 0 for multiple file selection in Safari 5.1

    The file size of selected file in input file control is shown as 0 for multiple file selection in Safari 5.1. If you select single file, then it is able to return file size correctly. However, if you select multiple files, then the file size of each of the selected file is always returned as 0 from javascript. This works correctly in Safari 4.0 but it does not work in Safari 5.1.
    How do I get the correct file size in Safari 5.1 ?

    If you want to post (or send me) a link to the lrcat file, I'd take a look at it for you, and give you a break-down what's consuming all the bytes. But it might be fun to learn how to do that yourself (e.g. using SQL). I use SQLiteSpy, but other people have their favorites.. (or you can use a command-line client if you prefer..). One way: just run "drop table "{table-name}" on each table then look at filesize (do this to a copy, not the real thing).
    Anyway, it's hard to imagine keywords and captions etc. taking much of the space, since even if you had 1000 10-character words of text metadata per photo average that still only adds up to 117MB, which isn't a substantial portion of that 8G you're seeing occupied.
    Anyway, if you've painted the heck out of most of them and not cleared dev history, that'll do it - that's where I'd put my money too...
    One thing to consider to keep file-size down:
    ===================================
    * After reaching a milestone in your editing, take a snapshot then clear edit history, or the top part of it anyway (e.g. leave the import step), using a preset like:
    Clear Edit History.lrtemplate
    s = {
        id = "E36E8CB3-B52B-41AC-8FA9-1989FAFD5223",
        internalName = "No Edit",
        title = "Clear Edit History",
        type = "Develop",
        value = {
            settings = {
                NoEdit = true,
            uuid = "34402820-B470-4D5B-9369-0502F2176B7F",
        version = 0,
    (that's my most frequently used preset, by far ;-})
    PS - I've written a plugin called DevHistoryEditor, which can auto-consolidate steps and reduce catalog size - it's a bit cumbersome to use a.t.m. but in case you're interested...
    Rob

  • How to edit the properties for existing variables in BEX query, so that I can get multiple input selections

    Dear fellow developers,
    I'm trying to edit an existing variable using BEX query, so that it can allow multiple input selections.
    As you can see in the screenshot attached, the option is selectable during creation.
    However, during editing of an existing field, this field (Details -> Basic Settings -> Variable Represents) is not selectable.
    Does anyone knows why, and how to remedy this?

    Yes you can do it at the table level.
    Go to SE11 enter table name as RSZGLOBV.
    Enter the technical name of variable in VNAM field..You need to change the value in VPARSEL column.
    Please make sure to get the where used list of this variable so that you can know the impact,if something goes wrong.
    Also change it in DEV and then transport across the landscape.
    PS:Same thing has been described in this blog as well
    Changing BI variable parameters
    Regards,
    AL
    Message was edited by: Anshu Lilhori

  • JTree multiple nodes selection problem !

    I can not make my JTree to be in multiple node selection mode.
    I have custom tree model and tree node class, the tree model class
    implements javax.swing.tree.TreeModel, and the tree node is an ordinary
    Java object.
    In this setting, my JTree is always in single selection mode.
    I have tried set the selection model after the JTree has initialized, and
    it didn't work.
    What I missed in TreeModel implementation ? Or should my tree node class
    also implements javax.swing.tree.TreeNode ?
    Don't tell me just call
    xxtree.getSelectionModel().setSelectionMode(javax.swing.tree.TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    It didn't work.

    Just in case anyone wants to know, I did find the magic number of files, and what the problem is. I talked with tech suppot at Adobe, and they know the problem exists, but won't fix it. I did put in a request in the "Request a Feature" form. Read on:
    The magic number is 40 Canon 1Ds Mark III Raw files, and clicking on three or more keywords. The key to not having the numbers of keywords counted incorrectly in the filter pane is to click on the keywords as fast as you can before it starts to write to the metadata. If you click on each keyword one at a time, and wait about a second or more between selecting the keywords, then the counts in the filter panel for the number of keywords is not correct in relation to the number of files that you have chosen to apply keywords to. The cure for this is to click as many keywords as possible as fast as you can before the software starts incorporating the keywords into the metadata.
    I would suggest to Adobe, that a nice feature would be that one could click on as many keywords as one would want, to as many files one would want, and then have a button or icon that would enable one to then apply all the keywords at once, instead of applying them as you click them as it is now. I also would love it if Adobe fixed it now instead of waiting to fix it in the version of CS5. Someone on Adobe's support line told me that Adobe would rather wait to put this into the CS5 version than fix it now. I don't think that is right, but heck, I am only one guy who depends on this software to provide images keyworded to my clients in a timely manner. I would never run my business like this Adobe. If there is a problem, and there is, please fix it now, or give me some of my money back since your product has a design flaw that is having a negative impact in my ability to to my job and run my business.
    Thanks!
    Daniel Root
    Portland, OR

  • Cannot have multiple items selected in a DropDownList when edit the forum in sharepoint

    hi ,
    i  have custom forum for new and edit, in new forum we have controls drop down values, when select drop down1   values that related values are displayed in dropdown2 , when edit  item  that  time we getting error
    Cannot have multiple items selected in a DropDownList.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.
    Source Error:
    HttpException (0x80004005): Cannot have multiple items selected in a DropDownList.]
    System.Web.UI.WebControls.DropDownList.VerifyMultiSelect() +124
    System.Web.UI.WebControls.ListControl.RenderContents(HtmlTextWriter writer) +10956501
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +42
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
    System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +13
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +42
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
    System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +42
    ASP._controltemplates_amat_appayrequest_webparts_appayrequest_appayrequestusercontrol_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES\AMAT.APPayRequest.Webparts\APPayRequest\APPayRequestUserControl.ascx:350
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +115
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
    System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +42
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
    System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +253
    System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +87
    System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +53
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
    System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +42
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
    System.Web.UI.Page.Render(HtmlTextWriter writer) +38
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4240

    Hello,
    Could you please share your code with us? Also explain how you are binding DDL.
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

Maybe you are looking for

  • N card for Powerbook 1.67GHz G4

    Does anyone know of any cards for the 15" G4 Powerbook 1.67GHz that will for sure work with the new Airport Extreme I just purchased. The speed is great on my iMac C2D and would like to get the Powerbook going at the same "N" speed. Thanks Chris iMac

  • Running Commerce Server 3.5 in Windows2000 as a service

    We are running Commerce Server 3.5 for Weblogic 6 SP2. I tried to run installNTService.cmd as specified in http://e-docs.bea.com/wls/docs60/adminguide/startstop.html#1026476, but it only seem to install the weblogic application server as a Windows se

  • PowerBook 12" magnetic latch problem

    I have searched the discussion board for similar problems to mine and while some of them were close, none of them had any answers that I would find helpful. So here's my problem. I've had my PowerBook for little over two weeks now, and the magnetic l

  • Complex SQL Cursor to update tables present as attribute in another table

    I want to write a cursor that fetches the table names which are actually present in a column in another parent table then update a particular column/attribute in each table. The parent table (say ABC has a column (say x) which holds the list of all t

  • Dialog to Action...

    Hi there, I'm trying to get used to writing my scripts with Adobe Story, since I'll soon be developing a tv series with writers all over the country. I really like the cloud-based project management, sharing, collaborations and commenting features -