Contiguous and non-contiguous multiple cell selection in JTable

I desparately need your help on this.
My appliaction contains a JTable. The users should be permitted to select multiple cells (both contiguous and non-contiguous) using
Ctrl + Click -- add that cell the already existing selection
Shift + Click -- add all cells in the range to the selection.
I like to have the selection behaviour as that in Excel (where you could ctrl + click on any cell to add it to selection).
Questions:
==========
Is this behavior possible using JTable?
How to do this?

Hi, use
JTable table = new JTable();
DefaultListSelectionModel  dlm =  new DefaultListSelectionModel();
dlm.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION  ); //1( the first one should be the one you are looking for)
or (choose 1 or 2, the rest stays the same)
dlm.setSelectionMode( ListSelectionModel.SINGLE_INTERVAL_SELECTION );//2
table.getColumnModel().setSelectionModel(dlm);
table.setCellSelectionEnabled(true);Hope this helps.
Greetings Michael.

Similar Messages

  • How to do Multi Cell Selection in JTable

    Dear Friends,
    Any body know Multi cell selection in jtable......
    Thanks

    Try overriding the changeSelection(....) method of JTable.
    public void changeSelection(int row, int column, boolean toggle, boolean extend)
         if (d.after(currentDate)
              super.changeSelection(row, column, toggle, extend);
    }

  • IRR and non-contiguous range

    I am looking to calculate an IRR with cash flows that are not in a single column or row.  I am wondering if Numbers can handle a non-contiguous range and if so, how?
    After experimenting a bit, I expected IRR((a, b:c, d), ) to work but it didn't. Instead, I got an error message that states, "The formula contains a list where a single argument is expected."
    I would suspect that dealing with (or not being able to handle) non-contiguous ranges is not an IRR issue but any function looking for range as an argument.
    Has anyone needed to do this and has done so successfully?
    -DaverDee

    you can make a single range by making a aux table which references all the non-contiguous data and makes it contiguous.:
    You could even do this in a different table, or sheet, to hide the non-contiguous data

  • Multiple Cell Selection Scaling Factor Issue within BEX

    We have a report which we need to create views from where each view is simply a different scaling factor within 20 rows of a 50 row query.  
    Within WEB reporting, you can simply select all the cells you want, and then select the proper scaling via the context menu.
    When you try to do the same thin in BEX though, only the first cell that is selected within the total selection is changed to the desired scaling factor selected.
    So...is this a bug?  ...and/or how can we selectively change the scaling for multiple cells within BEX?
    You can of course selectively choose which figures should have a specific scaling, but we need views saved and not queries for this....and to my knowledge you can't save views out of query designer.
    any thoughts?

    When you try to do the same thin in BEX though, only the first cell that is selected within the total selection is changed to the desired scaling factor selected.
    are you trying to do this with cell references or are you doing it for the entire row/ column ?
    you can create cell refernces for the cells that require differenr scaling factor in the query designer and then using cell properties you can define a scaling factor of your choice.
    To create a cell refence simply double click that cell OR right click>create new cell refernce.
    then you will be able to see cell properties where you can define desired properties.
    Hope this helps you.

  • Multiple Cell Selection inJTable

    I want to select multiple cells ( 4 consequent cells) with single mouse click.The problem is the 4 cells are getting selected ,but the border is being set to only one cell on which i clicked,but the selection background color is set to all the four.
    i want the border to be included for all the four cells ,so that it looks like i have selected a set of cells .
    waiting for a reply.
    please help.

    In order to accomplish this, you will have to drastically modify the UI delegate for JTable. The difference between the areas you are speaking of is that one is the 'selection' and the one with the border is the 'focus' cell which represents the 'anchor' of the selection.
    The actual routines that paint the table cells are marked as private in the BasicTableUI class, so that is not a workable solution.
    Let this be a lesson to all Java programmers (ahem) about making critical methods private!
    Mitch

  • Multiple Cell Selection in a JTable (again...)

    Hi All -
    I'm trying to get a JTable working well with the ability to select multiple cells in the way you'd expect to be able to (in Excel for example). By this I mean, hold down ctrl to add to a selection, hold shift to select between the last selection and the new one, be able to drag multiple regions with the mouse and have them be selected.
    I've seen lots of talk about this, for example on this thread:
    http://forum.java.sun.com/thread.jspa?threadID=619580&start=0&tstart=0
    (the code here will not work in the 'general' case, for example it doesn't really support dynamic table resizing)
    ...and found some pretty extensive code from here:
    http://www.codeguru.com/java/articles/663.shtml
    ...that kinda half works. (but the selection model is very strange once you get it running. Not at all what the average user would be used to)
    Does anyone have this working 100% with code they can share? It is very surprising to me that this is not the default behavior in Swing to be honest.
    I'm sure that I can come up with a solution for my situation, but I may as well not waste the time if someone already has something working for this.
    Thanks!

    If you have columnSelectionAllowed,rowselectionAllowed and cellSelectionEnabled then you can select cell by cell if you use the control key,
    Now the problem is, if you don't have input by your keyboard, in my case, I have a big table and I need to select diferent cells that match a certain criteria,
    jTable2.setRowSelectionInterval(j,j); //but this only works not for different rows 5 - 120 - 595
    I'm trying to use:
    jTable2.changeSelection()
    but still don't have good results....
    If any one could help to this matter will be really appreciated...
    thanks...

  • Problem in cell selection in JTable Java Swing

    hii
    I am using JTable that shows data from database. I have developed one functionality. I change one cell value and then select multiple cell. If I press F12 function key then it copies first selected value and past it to another selected cells. it is working properly but when I press F12 it sets the last selected cell in editable mode. I want that all cell which has been pasted should be selected (with default blue colour not in editing mode). I am using ListSelectionListener for JTable Cell Selection and KeyListener for F12 functionality.
    Please give some solution
    I can not override editCellAt Method because i have already extended JFrame. and i tried to do this with Jtable.getSelectedColumn and getSelectedRow it is displaying the same value, by this how can I get the particular area of selection means Row nd Column Selected.
    How would I know the current selection when user selects more than one cell???
    Thanks
    Edited by: 850979 on 11-Apr-2011 02:13
    Edited by: 850979 on 11-Apr-2011 03:59

    camickr wrote:
    Presumably, JTable installs an action for the F12 key that results in starting editing the last selected cell.
    There are no bindings for F12. See the [url http://www.camick.com/java/blog.html?name=key-bindings]Key Bindings listing. (...)
    Right.
    Of course it doesn't make sense that a F? key should invoke the editorI thought he meant F2 ("edit" on Windows), so that sounded natural.
    All KeyEvents are passed to the editor for the cell and the editor is psuedo invoked. That is, the caret is not placed on the text field used as the editor, but the character typed is added to the editor. You can then either use tab/enter to save the text or use the escape key to cancel the editing.Thanks for the explanation. I had never noticed (I kept on double-clicking my JTable cells when I wanted to edit them! :o)
    Of course it doesn't make sense that a F? key should invoke the editor, but this is a by product of all KeyEvents being forwarded so you don't have to have special Key Bindings for every character.You're right - as always.
    They (Sun) could have filtered out some of the keys such as those, though, because as noted by the OP the current behavior is unintuitive.
    To better control when the cell is editable based on the KeyEvent you can override the table with code like <snipped>
    As you suggested using a Key Binding will prevent this behaviour as well (but only for that key).Right again, but in this specific case that is acceptable (the developer wants to attach a specific behavior to a specific key only).
    OP here is an SSCCE of that second approach:
    public class TestKeyBindingsOnJTable {
        public static void main(String... args) {
            final DefaultTableModel dtm = new DefaultTableModel(new String[] {"A", "B"}, 0);
            dtm.addRow(new String[]{"A1", "B1"});
            dtm.addRow(new String[]{"A2", "B2"});
            dtm.addRow(new String[]{"A3", "B3"});
            JTable table = new JTable(dtm);
            table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), "clear");
            table.getActionMap().put("clear", new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    dtm.removeRow(0);
            JOptionPane.showMessageDialog(null, table);
    }Edited by: jduprez on Apr 8, 2011 9:36 PM

  • How to restrict the cell selection in JTable based on cell contents...

    Hi all,
    I have some problem related to table cell selection.
    I have a table that represets the calendar of some month and year.
    I have the restriction that at one time only one cell could be selected.
    Now i want the cell seletion like this,
    I want only those dates to be selected if that date is after 'today'.
    that is I want to restrict the selection of previous dates.
    how can i do this.
    I have overridden the table methods like this, still no use.
    table = new JTable(model) {
    setOpaque(false);
    setSurrendersFocusOnKeystroke(false);
    setRowHeight(20);
    JTableHeader header = getTableHeader();
    header.setOpaque(false);
    getTableHeader().setReorderingAllowed(false);
    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    getTableHeader().setResizingAllowed(false);
    setCellSelectionEnabled(true);
    setFocusable(true);
    setBackground(new Color(247, 251, 255));
    setFont(newFont);
    public boolean isCellEditable(int row, int col) {
    return false;
    public boolean isCellSelected(int row, int col) {
    int r = getSelectedRow();
    int c = getSelectedColumn();
    String val = (String)getValueAt(r,c);
    Calendar cal = Calendar.getInstance();
    cal.set(currentYear+1900, month,Integer.parseInt(val));
    Date d = cal.getTime();
    Date currentDate = new Date();
    if (d.before(currentDate)) {
         return false;
    } else {
         return true;
    Someone please help...
    -Soni

    Try overriding the changeSelection(....) method of JTable.
    public void changeSelection(int row, int column, boolean toggle, boolean extend)
         if (d.after(currentDate)
              super.changeSelection(row, column, toggle, extend);
    }

  • 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

  • Numbers' Functions and Formulas in Multiple Cells, Tables, and Sheets

    Hello,
    I'm stuck with specifics that center around usage, and I get the funny feeling I'm overlooking a simple detail or two.
    If I may, here goes.
    I'm working with a single spreadsheet that has several sheets within it, and each sheet has an identical table. Each table is used to record various data, and I use an additional table in a separate sheet to consolidate some of the information, so that I can track results, at a glimpse, by looking at averages, totals, etc.
    Each data table is organized for consolidation by tracking wins, ties, or losses. It is important to know that each data table only records a single win, tie, or loss along with its other applicable data. And on the actual consolidation table I am trying to tally specific data fields by the use of Numbers' functions and formulas, yet I wish to keep these tallied results organized by the determining factor of whether or not they were gathered from a table that recorded a win, a table that recorded a tie, or a table with a loss.
    To illustrate, each table contains data fields that record start time, finish time, elapsed time, the day of the week, etc. Let's say I have eight tables, and the first two are winning tables, three more are tables that record a tie, and the last three are losing tables. For example, on my consolidated data table I wish to enter a function and formula capturing which of the eight tables are wins, ties, and losses so that I can, at a glance, see how much time elapsed to obtain the wins, ties, and losses. So then, in this example, for wins I want to determine which of those wins took 20 minutes, or which of them took 15 minutes, etc. So then, out of the two wins, let's say both of them took 20 minutes each. I need the numeral 2 to be counted and recorded on the consolidation table since only two tables match the criteria. And I would do the same for all remaining data fields (e.g., start time, finish time, etc.). Just so long as everything is determined by wins, ties, and losses, and then organized by the respective data fields. Simply put, this example determines a total of two wins that meet the data field requirement of 20 minutes. Out of the eight tables (one table per sheet) any other wins would then be organized according to the specific data in the elapsed time data field on it's data table (e.g., 5 minutes, 15 minutes, etc.).
    The exact syntax structure of the functions and formula I'm unsuccessfully using follows below. It only seems to return a result of 1, and I think it is returning this value from the IF Statements. By the way, the Win, Tie, or Loss cell in each data table is cell formatted as a pop-up so I can either select None or 1. But in this example I'm basing this on the time period of 20 minutes, and out of the eight data tables I have two wins which also record the time period as 20 minutes, so I should see 2 and not 1 in the 20 minutes column of the consolidated data table. Also, I tried changing the syntax where I would type "=1" in the IF Statements, but it returned a result of =1, and if I don't include the equals sign and quotation marks the result just shows up as 1.
    My Syntax:
    IF(Trade 1::'Data Recorded (1)' '* Win', 1, IF(Trade 2::'Data Recorded (1)' '* Win',1, IF(Trade 3::'Data Recorded (1)' '* Win',1, IF(Trade 4::'Data Recorded (1)' '* Win',1, IF(Trade 5::'Data Recorded (1)' '* Win',1, IF(Trade 6::'Data Recorded (1)' '* Win',1, IF(Trade 7::'Data Recorded (1)' '* Win',1, IF(Trade 8::'Data Recorded (1)' '* Win',1, IF(COUNTIFS(Trade 1::'Data Recorded (1)' '* Time in Trade (in minutes)', "=20m")+COUNTIFS(Trade 2::'Data Recorded (1)' '* Time in Trade (in minutes)', "=20m")+COUNTIFS(Trade 3::'Data Recorded (1)' '* Time in Trade (in minutes)', "=20m")+COUNTIFS(Trade 4::'Data Recorded (1)' '* Time in Trade (in minutes)', "=20m")+COUNTIFS(Trade 5::'Data Recorded (1)' '* Time in Trade (in minutes)', "=20m")+COUNTIFS(Trade 6::'Data Recorded (1)' '* Time in Trade (in minutes)', "=20m")+COUNTIFS(Trade 7::'Data Recorded (1)' '* Time in Trade (in minutes)', "=20m")+COUNTIFS(Trade 8::'Data Recorded (1)' '* Time in Trade (in minutes)'))))))))))
    Please bear in mind that the COUNTIFS portion of the above syntax structure is something I'm already successfully using to count the totals of other things not mentioned above, and I'm hesitant to delete it since it already works to my satisfaction when I want to, for example, determine the total number of overall wins. So, just for illustration purposes, I might have an overall wins column in my consolidation table that records how many wins there are, regardless of organization by elapsed time, or any other data field. In other words, the COUNTIFS syntax structure already works to my satisfaction. I'm not sure if it's possible to alter it so that it isn't so long, but what's there does work just when counting total numbers, as just mentioned.
    In summary, I'm wondering which function I can use with the COUNTIFS function to determine which of my eight data tables are winning tables, but break those wins down further based on criteria like elapsed time, and in the above example the time elapsed is 20 minutes. As you may see above, I'm unsuccessfully using the IF function. Finally, I've looked at the function browser descriptions of things like LOOKUP, HLOOKUP, VLOOKUP, INTERSECT.RANGES, and a few others. And so far I haven't made good use of any of them the way I've done when I use the COUNTIFS function by itself when only counting overall totals. But now I must determine totals that meet certain criteria, as explained above.
    Please help if you dare (smile). This is a huge project I'm undertaking, and so as not to cause confusion I have not included all of the details. But rather, I've taken a small sampling and set it to the side for experimentation. If this small sample works out to my satisfaction I can simply copy and paste the syntax in all other respective cells in the consolidation table, changing only reference locations, and perhaps conditions or values. One thing is certain, I don't intend on giving up on it.
    Thank you for your time and advice.
    Blessings!
    Message was edited by: solo68
    Added image.

    I'd like to edit the last paragraph of my second posting, but for some reason an entirely new posting is being created when I attempt to do this. So when reading this post, please use it to replace only the last paragraph of my second post containing the four inserted images.
    Last paragraph begins:
    In closing, I need each cell in each column of each row in my consolidation table to remain as is. I have my reasons for doing this, and they all serve a specific purpose. The only exception would be the formatting of the last three rows as footer rows. Most importantly, and I should have made this abundantly clear earlier, my apologies, I need a single function and formula in cell E7 of my consolidation table that will firstly determine which data tables are winning tables while secondly and simultaneously counting which of those winning tables have elapsed times of 20 minutes. Perhaps, now this better explains why my syntax is written the way it is written. In the example I provided, if the proper function and formula were written it would result as 2 in cell E7 in my consolidation table. If there is anything else specific you need of me in order to assist me, please request it. Thank you.
    Last paragraph ends:
    Additionally, to t quinn:
    First off, thank you for returning to assist me. I really do appreciate your efforts. Please be aware that I'm avoiding going into details about each and every portion of my spreadsheet because I wish to avoid discussion that is off topic. As I stated earlier, I'm new to using these features of Numbers. My spreadsheet encompasses a much larger amount of data than I'm referring to in the example in my first post. But in my example I'm isolating just the information concerning what I'm now trying to accomplish to finish my spreadsheet project. Moreover, most of what I've done up to this point I was able to figure out on my own, or get help from watching videos on YouTube, or simply using the application help menu. Please be aware that I consulted all of these, repeatedly. I even contacted AppleCare, and was told this sort of support is not available. In spite of this, I've accomplished a great deal in my first large spreadsheet project. Please be aware that when I wrote my second post and specifically responded to you, I didn't want to be rude or ungrateful, and I still don't, but maybe the suggestions you and Hiroto made about gathering the count of wins, ties, and losses are something I've already done. I think I've done that separately. These counts are already in separate cells, and they are working fine. In my first post where I inserted only one image you can see examples of this in my consolidation table image, in cells B3 and E6. I apologize for not making this abundantly clear earlier. Furthermore, the portion of my syntax that shows the COUNTIFS is the exact way I accomplished this, and it is written the way it is written because I need separate sheets, each with their own data tables. Again, in cell E7 I need to determine which of the eight data tables that record wins are also recording 20 minutes, but I need this in a single function and formula with the result appearing only in cell E7. Once this is figured out I will adjust the syntax to do the same thing with every column (these are not shown but they exist) in my consolidation table for the last three footer rows, named Win Column Totals, Tie Column Totals, and Loss Column Totals. The last three rows being footer rows may not be necessary, and if so, I can convert them back to normal rows. Nonetheless, my consolidation table is counting the totals of all data in all data tables. This much I've already accomplished. Now I have one last function and formula I'm working on in order to determine which of the eight data tables record wins, ties, or losses while it simultaneously counts which of the wins, ties, or losses fall within certain categories like elapsed time, and this will be shown on my consolidation table only in the last three rows. Yes, I've gotten the total wins counted, and separately counted the total number of times 20 minutes was the elapsed time used, but so far, just looking at my consolidation table I don't know if the total number of times 20 minutes was used was with a win, tie, or loss. That's what I need to know now. Everything else is already accomplished. So then my consolidation table will show the totals for all data fields in my eight data tables as illustrated in cells B3 and E6. The last three rows of my consolidation table will break this down in a single function and formula with one row for wins, a second for ties, and a third for losses. And each of these respective last three rows will in the same function and formula determine if the win, tie, or loss also is one of the data fields in my eight data tables. How? By the use of columns in my consolidation table. Remember, each of my eight data tables are identical. In the example in my first post I only used one data field, elapsed time (Time in Trade), to illustrate in one column on my consolidation table what I'm trying to accomplish with all of the columns not shown in my consolidation table. Once this is figured out I can adjust it to complete the remainder of the consolidation table. Thank you, t quinn.
    To all reading this and attempting to offer assistance, if for any reason I'm still not explaining myself clearly, please continue to ask me more specific questions. I realize it's hard to communicate this way, and if Apple allowed us to upload the actual spreadsheet it would make this entire forum a better place to communicate. But that's going off topic, so let's simply focus on the matter at hand. Thank you.
    Blessings!

  • Make editable and non-editable some cells in ALV OO

    Hello Experts, i have a table like this:
    KUNNR DATE VALUE1
    And a search button that obtains data, and then display the information in the ALV, like this
    KUNNR DATE       VALUE1
    1000     1.1.2009    A
    1001     2.2.2009    B
    Also i have a button that append  an empty line to the ALV
    I want that the kunnr retrieved in the search be non-editable
    But i want that the kunnr cell in the appended line be editable
    How can i do this?
    THANKS!
    Edited by: Mariano Gallicchio on Jun 26, 2009 3:45 PM

    when (sy-ucomm for New row)
    LOOP AT <fcat> into <workarea>
       CASE <workarea>-fieldname.
          WHEN 'KUNNR'.
    * Making a column as Editable
            <workarea>-edit = 'X'.
        ENDCASE.
      ENDLOOP.
    Kanagaraja L
    Edited by: Kanagaraja  Lokanathan on Jun 26, 2009 4:01 PM
    Edited by: Kanagaraja  Lokanathan on Jun 26, 2009 4:02 PM

  • Changing the Height and Width of Multiple Cells

    Is there a way of selecting a group of cells and making them a specified height and width? It would make my life so much easier when producing large tables!
    Any help appreciated.
    Regards,
    Adam Colvin

    Hi Adam,
    Select the block of cells.
    Open the Inspector.
    Choose the Table inspector.
    Set the row height and column width using the appropriately labeled controls.
    Regards,
    Barry

  • Multiple cells selection after research

    Hi to everyone,
    i'm trying to create a function word-find into a JTable (like the fuction - find on this page CTRL F).
    Now my method, when there are two or more same objects in the table, selects(with a differrent cell background) only the last one object find.
    How can I select all the right elements found?
    I hope I've been enough clear.
    Thanks a lot for the help
    Jas

    Thanks for the suggestion, but in this case is not
    the best solution, because I would have to modify
    several classes.
    This function would be only an added to one already
    existing application that contain many classes.Well the JXTable extends JTable, so the change would be minor
    Wouldn't be an other possibility/solution?Other than using something already created by someone else?

  • Multiple Row selection In JTable

    I am working with JTable and JList, I can transfer element from table to list and vise versa on clicking on button, my problem is that when i transferred element to either of them that should be selected. i can also transfer multiple item at time and doing sorting with table if i am adding element of 1st row and last row of table, both the rows should be selected.
    Any thoughts!!!!!!!!!!!
    ThnX
    Prashant_SDN

    Thnx for response and selection in list is done sucessfully.
    I have one additional query, I am transfering element from list to table and did use sorting so rows did not get added after existing row of table but added as per sorting.
    so how do i get the index of newly added row after sorting.
    Any thoughts!!!!

  • Mulitple Cell selection  with unselect the same Cell

    Dear Friends,
    I am having a JTable with a Multiple Cell Selection .Consider Now iam
    selecting the cell (0,3) (0,5) (1,7).When selecting the cell it is in Red color.
    I made this multi selection by using the setCellRenderer method overriding.It works fine.
    Now I am clicking the Same above cell with right click button in the mouse ..it must unselect ....means It may change the color too.
    Any body know about this....Can u please help me ...This is very urgent for me........
    Kindly
    malar

    Thanks friend,
    I have finished that..Now its working fine....
    I used the same cell renderer with deleting the existing index which was selected....And I called the repaint() again....Now it unselected.
    Thanks for ur simple and cute Idea....Thanks a lot

Maybe you are looking for

  • Where did boot camp go?

    Ok I installed Windows 8.1 on my 13" Macbook Pro 2012 non retina about 4-5 months ago. Today I decided to also install Ubuntu 14.04. I'm not sure where it went wrong, but now when I hold the option key while booting the only drives that come up are M

  • Maintain number range interval "01" for inventory documents

    hi, when i am creating a physical inventory creating document t.code LI01 i got this eror: Maintain number range interval "01" for inventory documents.where i have to maintain please reply me. naveen

  • Why use narrow?

    One difference which I observed between RMI and RMI/IIop was teh use of narrow. My question is why to use narrow rather than directly casting an object to interface extending remote.

  • How do I download and run Photoshop?

    How do I download and run Photoshop on my computer.  I have the serial number for Creative Suite Premium.  Will that allow me to download Photoshop from the Creative Cloud?

  • Squiggly spell checking component

    Hi everyone, Following the release of Squiggly - the spell checker engine for mx components - I just realized a small Flex4/Spark component for using the spell checker with a TextFlow. The demo here: http://lafabrick.com/labz/pageLayout/squiggly/. So