Fully independent cell selections

I have been working thru the Swing Tables tutorial to learn how to select nonadjacent cells as would be needed in a week calendar (viewed as a 7 x 24 table) to select a 3rd shift � e.g., Monday 3rd shift is Monday 2300 thru Tuesday 0700. I see two notes in the tutorial that makes me think that is �not in the cards�, so to speak, with JTable. Here is the note from the tutorial:
NOTE: JTable uses a very simple concept of selection, managed as an intersection of rows and columns. It was not designed to handle fully independent cell selections.
NOTE: Setting cellSelectionEnabled to a value has the side effect of also setting both rowSelectionEnabled and columnSelectionEnabled to that value. Setting both rowSelectionEnabled and columnSelectionEnabled to a value has the side effect of also setting cellSelectionEnabled to that value. Setting rowSelectionEnabled and columnSelectionEnabled to different values has the side effect of also setting cellSelectionEnabled to false.
Fair enough; JTable is not the answer. Unfortunately, the tutorial does not offer any hints about how to manage fully independent cell selection. So far, there does not appear to be a way to add that support by customizing a Table Model.
Anybody have any ideas about what else to use?

Use this code and change it as appropriate.
<table style="width: 100%" border="1" class="style1">
                <tr>
                                <td style="width: 33%"> </td>
                                <td style="width: 33%"> </td>
                                <td style="width: 34%"> </td>
                </tr>
                <tr>
                                <td style="width: 33%"> </td>
                                <td style="width: 33%"> </td>
                                <td style="width: 34%"> </td>
                </tr>
                <tr>
                                <td style="width: 33%"> </td>
                                <td style="width: 33%"> </td>
                                <td style="width: 34%"> </td>
                </tr>
</table>
<table style="width: 100%" border="1" class="style1">
                <tr>
                                <td colspan="2" style="width: 50%"> </td>
                                <td style="width: 50%"> </td>
                </tr>
                <tr>
                                <td colspan="2" style="width: 50%"> </td>
                                <td style="width: 50%"> </td>
                </tr>
</table>
hth

Similar Messages

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

  • Cell selectable in table

    Hi everybody,
    is it possible to make a single cell selectable in a  table in Web Dynpro for ABAP?
    In simple ABAP it is possible and you can catch the coordinate while raising an event (button).
    In Web Dynpro when I am using "input fields" instead of "text view" for the cell editor I can go into a cell, but it isn't selected.
    By the way the table should not be editable ...
    Thanks for all answers ...

    Problem is solved.
    Solution:
    As described I have a context attribute "marked_cell" typed WDR_EXT_ATTRIBUTE_POINTER.
    After selecting a cell my method behind the button could read the coordinates with the following code.
      DATA lo_el_context    TYPE REF TO if_wd_context_element.
      DATA ls_context       TYPE wd_this->element_context.
      DATA lo_marked_cell   LIKE ls_context-marked_cell.
      DATA lv_marked_column TYPE string.
      DATA lv_marked_row    TYPE string.
    * get element via lead selection
      lo_el_context = wd_context->get_element(  ).
    * get single attribute
      lo_el_context->get_attribute(
        EXPORTING
          name =  `MARKED_CELL`
        IMPORTING
          value = lo_marked_cell ).
    * lo_marked_cell contains direkt the column
      lv_marked_column = lo_marked_cell-attribute_name.
    * Additionaly we need the row number the user selected
      lv_marked_row = lo_marked_cell-element->get_index( ).

  • 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

  • Jtable in cell how to single mouse click make the cell selected.

    it seems need double click make cell selected.
    thanks!!!

    Hi,
    these link will help you.
    It has code for both examples, with 1 click and with 2 clicks:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=362073&tstart=0&trange=15
    sergio.

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

  • 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

  • Cell Selection & ALV Table (SALV_WD_TABLE)

    Hi Experts,
    is it possible to select  more than one cell (not row!) in an ALV Table?
    I changed the cell editor to cl_salv_wd_uie_input_field and set the whole table editable.
    Now I am able to select one cell, but what about multiple selections? In the Java world I found this one: TableSingleMarkableCell
    Sounds good - what about ABAP?
    And if there is no way with the ALV Table, how I might get the functionality with other components?
    Thanks for your help, have a great week!
    Hendrik
    Edited by: Gedicke, Hendrik on Jul 28, 2008 11:06 AM

    Hi Thomas,
    I tried to integrate the cell variant TableSingleMarkableCell. But I think the ALV table does not support this cell variant, or am I wrong? The runtime class is .CL_WD_TABLE_SNGL_MARK_CELL
    (see http://help.sap.com/saphelp_nw70/helpdata/EN/a5/b8fa41c915da6fe10000000a1550b0/frameset.htm)
    I will try to explain:
    When you want to use a cell variant, it is necessary to "add" it to a column. Therefore you can use the public method "ADD_CELL_VARIANT" of the class "CL_SALV_WD_COLUMN".
    This method has got a "value" import parameter which is a referencing the class "CL_SALV_WD_CV".
    The thing is that the only sub class of "CL_SALV_WD_CV" is "CL_SALV_WD_CV_STANDARD" and this means that the TableSingleMarkableCell is not supported.
    Or did I made a mistake? This is my last chance to use a cell selection with the alv component.
    Thanks & Regards,
    Hendrik

  • How to catch change cell selection in a JTable?

    I'm using a ListSelectionListener with a JTable to catch the list selection changes but it only detects row changes, and if i select a different cell but within the same row it does not trigger the event.
    Do you guys know a way to detect this event?
    Thanks!!!

    I'm using a ListSelectionListener with a JTable to catch the list selection changes but it only detects row changes,Try adding a listener for the columns as well:
    table.getTableHeader().getColumnModel().getSelectionModel().addListSelectionListener(...);

  • How to listen for cell selection changes within a JTable

    Problem: my table has 8 columns, with 4 of them containing very large text (up to 1000 chars). Solution is to set the initial size these columns so that the 1st 20 chars are visible, and if one of these columns gains focus/selection via mouse-clicking/tabbing/arrow keys, the entire text is shown in a JTextArea below the table.
    I added a ListSelectionListener to the table, but this only informs me when the row selection has changed.
    I added a FocusListener to the table, but this only informs me when the table gains/loses focus, not when it's been changed within.
    I added a TableColumnModelListener to the TableColumnModel, but this only informs me when the column selection has changed.
    I didn't bother with MouseListener as this won't handle change of selection via tabbing.
    The LSL got me half way there, and the TCML got me the other half. Any ideas on how to combine?
    Or is there something obvious that I'm missing?

    Walter Laan wrote:
    Use both and call the same method which updates the text area based on the current selected (or focused == lead selection index) cell.Yeah - that's what I figured. I just didn't know if there was a magic bullet (i.e., a single listener) out there that I was missing.
    While you are at it, also add a table model listener which calls the same method if the selected cell is updated.I'll keep that in mind, but it's not necessary in this particular case. The table cells in question will be uneditable. The text area will have supporting Edit/Save/Cancel buttons.

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

  • Table cell selection border

    hi,
    how can you find out the default color of the table cell renderer border?
    when you select a cell in a JTable, there's (by default) a thin border drawn around it. since i use my own renderer for some columns, i need to find out the color of this border (it is differnt for different look & feels).
    thanksout the default

    you were right. thank you.
    just one more thing: where can i find the names of all those properties that the UIManager uses? like the one you used "Table.focusCellHighlightBorder"...

  • 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?

  • Right click table cell selection

    I'm making a GUI interface including a table. What I'd like to implement is ability to right click on the cell and open the options selection, similar as to when right click the icon on the desktop. Any ideas ?

    You will need to create the component that will show your options and then add a MouseListener to your table that detects the mouse event and shows your options.
    A good place to start would be to have a look at this link: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    And here: http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html

  • 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

Maybe you are looking for