Multiple selection of row in a jtable

Hello All,
I am working with this jtable 'tblSearch'. The application requirement is that the user should have the ability to select multiple rows using the control key. I am using the bold part of the code to color the selected row light gray. Can you someone help me to select multiple rows by holding the control key down.
    public void PopulateAS400(){
        cmbView.hidePopup();
        setCursor(hourglassCursor);
        int scrPos = scpSearch.getHorizontalScrollBar().getValue();
        oapprovalSQL = SQLFactory.createOrderApprovalSql();
        Vector FreightList = oapprovalSQL.getData(getAs400SearchString(), getOrderby(), AS400, AS400Overide.length, searchItems, rdoMatchAny.isSelected());
        columnNames = (Vector)FreightList.get(1);
        data = (Vector)FreightList.get(0);
        model = new DefaultTableModel(data,columnNames) {
            public Object getValueAt(int row, int col) {
                return super.getValueAt(row,col);
            public boolean isCellEditable(int row, int col) {
                if (row == 0){
                    getTblSearch().setColumnSelectionAllowed(true);
                    return true;
                getTblSearch().setColumnSelectionAllowed(false);
                return false;
           public Class getColumnClass(int c) {
               if(c == 5 || c == 9){
                    return BigDecimal.class;
               }else{
                    return String.class;
        JTable tmp = new JTable(model)
            private final KeyStroke tabKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
            private final KeyStroke shiftTabKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,KeyEvent.SHIFT_DOWN_MASK);
            public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
                AWTEvent currentEvent = EventQueue.getCurrentEvent();
                if(currentEvent instanceof KeyEvent)
                    KeyEvent ke = (KeyEvent)currentEvent;
                    if(ke.getSource()!=this)
                        return;
                    if (KeyStroke.getKeyStrokeForEvent(ke).equals(tabKeyStroke))
                        if (rowIndex > 0)
                            rowIndex = 0;
                            columnIndex = 0;
                            toggle = false;
                            extend = false;
                            getTblSearch().setColumnSelectionAllowed(true);
                    else if (KeyStroke.getKeyStrokeForEvent(ke).equals(shiftTabKeyStroke))
                        if (rowIndex > 0)
                            rowIndex = 0;
                            columnIndex = getTblSearch().getColumnCount()-1;
                            toggle = false;
                            extend = false;
                            getTblSearch().setColumnSelectionAllowed(true);
                        else if (columnIndex == getTblSearch().getColumnCount()-1)
                            rowIndex = 0;
                            columnIndex = getTblSearch().getColumnCount()-1;
                            toggle = false;
                            extend = false;
                            getTblSearch().setColumnSelectionAllowed(true);
                super.changeSelection(rowIndex, columnIndex, toggle, extend);
            public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColumnIndex)
                Component c = super.prepareRenderer(renderer, rowIndex, vColumnIndex);
                if ((vColumnIndex == 7) && (rowIndex > 0))
                    if ((model.getValueAt(rowIndex,7) != null) && (model.getValueAt(rowIndex,7).toString().equalsIgnoreCase("NMI")))
                        c.setBackground(Color.red);
                    else if ((model.getValueAt(rowIndex,7) != null) && (model.getValueAt(rowIndex,7).toString().equalsIgnoreCase("NMI ANSWERED")))
                        c.setBackground(Color.green);
                    else
                        c.setBackground(Color.white);
                else
                    c.setBackground(Color.white);
                **if (isRowSelected(rowIndex) && (rowIndex > 0)){**
                    **((JComponent)c).setBackground(Color.LIGHT_GRAY);**
                if (rowIndex == 0 && isCellSelected(rowIndex, vColumnIndex)) {
                    c.setBackground(lightBlue);
                return c;
        setTblSearch(tmp);
        getTblSearch().setAutoscrolls(true);
        getTblSearch().setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        getTblSearch().setAutoCreateColumnsFromModel(false);
        getTblSearch().setColumnSelectionAllowed(false);
        getTblSearch().setRowSelectionAllowed(true);
        getTblSearch().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        JTableHeader header8 = getTblSearch().getTableHeader();
        ColumnHeaderListener colH8 = new ColumnHeaderListener();
        colH8.setCallFrom("OrderApproval");
        colH8.setOapproval(this);
        header8.addMouseListener(colH8);
        header8.setReorderingAllowed(false);
        header8.setResizingAllowed(false);
        getTblSearch().getColumn("Co #").setCellEditor(asCompCell);
        getTblSearch().getColumn("Reg").setCellEditor(asRegCell);
        getTblSearch().getColumn("Rep #").setCellEditor(asRepCell);
        packColumns(getTblSearch(), 1);
        getTblSearch().getColumnModel().getColumn(6).setPreferredWidth(240);
        for(int i=0; i<searchEntries8.length; i++) {
                getTblSearch().setValueAt(searchEntries8,0,i);
((GenericTextEditor)getTblSearch().getCellEditor(0,i)).setCellEditorValue(searchEntries8[i]);
scpSearch.add(new PopupContainer());
popupMenu = new JPopupMenu();
JMenuItem printFinalOrderMenu = new JMenuItem(PRINTFINALORDER_CMD);
printFinalOrderMenu.addActionListener(new PrintFinalOrderMenuListener());
popupMenu.add(printFinalOrderMenu);
MouseListener popupListener = new PopupListener();
getTblSearch().addMouseListener(popupListener);
scpSearch.setViewportView(getTblSearch());
scpSearch.getHorizontalScrollBar().setValue(scrPos);
setCursor(normalCursor);
Thank you all for your time n help.
Edited by: anjan_dev on Jan 29, 2008 2:14 PM
Edited by: anjan_dev on Jan 29, 2008 2:15 PM
Edited by: anjan_dev on Jan 29, 2008 2:16 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

The issue is when I have one row already selected and then when I click on another row while holding the control key down. Our application needs an user to be able to select multiple rows at the same time.That is the default behaviour. I have no idea why it doesn't work for you.
Get rid of all your custom KeyEvent logic and try it again.
If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
http://homepage1.nifty.com/algafield/sscce.html
Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
http://forum.java.sun.com/help.jspa?sec=formatting

Similar Messages

  • Multiple selection of rows in webdynpro

    Hi All,
    How can we achieve the multiple selection of rows in a table in webdynpro and delete the same.
    If i have a table with 4 rows i have selected 2 rows and i have to delete those 2 rows.
    Thanks in Advance,
    Bsreddy.

    Hi Srinivas,
    Steps to make multiple rows selectable in table:
    1) Create the selection property of the node that you are binding to the table as o..n
    2) Un-check the, "Initialization Lead Selection" checkbox for the node which you are using to bind to the table
    3) In the Layout go to the table & specify selection mode as MULTI_NO_LEAD. It is important that you set the selection mode to MULTI_NO_LEAD or else in the end you would be capturing 1 row lesser than the total number of rows the user has selected. This is because 1 of the rows would have the LeadSelection property & our logic wouldn't be reading the data for that row. Check the example code fragment as shown below:
    Steps to get the multiple rows selected by the user:
    In order to get the multiple rows which were selected by the user you will just have to call the get_selected_elements method of if_wd_context_node.  First get the reference of the node which you have used to bind to the table & then call this method on it. Check the example code fragment below:
    METHOD get_selected_rows .
      DATA: temp TYPE string.
      DATA: lr_node TYPE REF TO if_wd_context_node,
                wa_temp  TYPE REF TO if_wd_context_element,
                ls_node1 TYPE wd_this->element_node_flighttab,
                lt_node1 TYPE wd_this->elements_node_flighttab.
      lr_node = wd_context->get_child_node( name = 'NODE_FLIGHTTAB' ).
    " This would now contain the references of all the selected rows
      lt_temp = lr_node->get_selected_elements( ).
        LOOP AT lt_temp INTO wa_temp.
    " Use the references to get the exact row data
          CALL METHOD wa_temp->get_static_attributes
            IMPORTING
              static_attributes = ls_node1.
          APPEND ls_node1 TO lt_node1.
          CLEAR ls_node1.
        ENDLOOP.
    ENDMETHOD.
    So now lt_node1 containes information about all the rows which are selected by the user.

  • How to apply List box for multiple selection of rows  in ALV report ?

    Hi Exprots,
    1: How to apply List box for multiple selection of rows  in ALV report ?
    Thanking you.
    Subash

    hi,
    check the below program.
    REPORT zalv_dropdowns.
    *Type pools declarations for ALV
    TYPE-POOLS : slis.
    *data declarations for ALV container,ALV grid, Fieldcatalogues & layout
    DATA: g_grid  TYPE REF TO cl_gui_alv_grid,
          g_custom_container TYPE REF TO cl_gui_custom_container,
          gt_fieldcat TYPE lvc_t_fcat,
          gs_layout TYPE lvc_s_layo.*INTERNAL TABLE AND WA DECLARATIONS FOR t517 A table
    DATA: gt_outtab TYPE STANDARD TABLE OF t517a INITIAL SIZE 0,
          wa_outtab TYPE t517a.
    START-OF-SELECTION.*Call to ALV
      CALL SCREEN 600.*On this statement double click  it takes you to the screen painter SE51.
    *Create a Custom container and name it CCONT and OK code as OK_CODE.
    *Save check and Activate the screen painter.
    *Now a normal screen with number 600 is created which holds the ALV grid.
    PBO of the actual screen , Here we can give a title and customized menus
    Here we also call the subroutine for ALV output.
          MODULE PBO OUTPUT                                             *
    MODULE pbo OUTPUT.
      PERFORM alv_output.
    ENDMODULE.                    "pbo OUTPUT
          MODULE PAI INPUT                                              *
    MODULE pai INPUT.
    ENDMODULE.                    "pai INPUT
    *&      Form  BUILD_FIELDCAT
    FORM build_fieldcat.
    DATA ls_fcat TYPE lvc_s_fcat.
    *Build the field catalogue
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'T517A'
        CHANGING
          ct_fieldcat      = gt_fieldcat.
    To assign dropdown in the fieldcataogue
      LOOP AT gt_fieldcat INTO ls_fcat.   
    CASE ls_fcat-fieldname.
       WHEN 'SLART'.
    *is the first list box
            ls_fcat-drdn_hndl = '1'.
            ls_fcat-outputlen = 15.
            MODIFY gt_fieldcat FROM ls_fcat.
    is the second list box    
    WHEN 'ABART'.       
            ls_fcat-drdn_hndl = '2'.
            ls_fcat-outputlen = 15.
            MODIFY gt_fieldcat FROM ls_fcat.   
    ENDCASE.
      ENDLOOP.
    ENDFORM.                    "build_fieldcat
    *&      Form  ALV_OUTPUT
    FORM alv_output .*Create object for container
      CREATE OBJECT g_custom_container
             EXPORTING container_name = 'CCONT'.
    *create object for grid
      CREATE OBJECT g_grid
             EXPORTING i_parent = g_custom_container.
    Build fieldcat and set column
    *Assign a handle for the dropdown listbox.
      PERFORM build_fieldcat.
    *Build layout
      PERFORM build_layout.
    Define a drop down table.
      PERFORM dropdown_table.
    *fetch values from the T517A table
      SELECT * FROM t517a INTO TABLE gt_outtab.
    *Display ALV output
      CALL METHOD g_grid->set_table_for_first_display
        EXPORTING
          is_layout       = gs_layout
        CHANGING
          it_fieldcatalog = gt_fieldcat
          it_outtab       = gt_outtab.ENDFORM.                               "ALV_OUTPUT
    *&      Form  dropdown_table
          text
    -->  p1        text
    <--  p2        text
    FORM dropdown_table.*Declarations for drop down lists in ALV.
      DATA: lt_dropdown TYPE lvc_t_drop,
            ls_dropdown TYPE lvc_s_drop.
    First SLART listbox (handle '1').
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '01 Primary school'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '1'.
      ls_dropdown-value = '02 Lower Secondary'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '1'.
      ls_dropdown-value = '03 Upper Secondary'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '04 Professional School'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '05 College'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '06 University'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '09 Other Establishment'.
      APPEND ls_dropdown TO lt_dropdown.* Second ABART listbox (handle '2').  ls_dropdown-handle = '2'.
      ls_dropdown-value = '10 Primary School certificate'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '2'.
      ls_dropdown-value = '20 Lower secondary/Junior high'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '30 High school diploma(B-levels)'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '2'.
      ls_dropdown-value = '31 Vocational'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '32 Matriculation'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '40 Specialist vocational certificate'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '50 College degree Level1'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '51 College degree Level2'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '52 Masters degree'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '60 Univ Degree level1'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '61 Bachelors degree'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '62 Masters degree'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '63 Licenciate'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '64 Doctors Degree Ph.D'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '89 None'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '90 Unknown'.
      APPEND ls_dropdown TO lt_dropdown.*method to display the dropdown in ALV
      CALL METHOD g_grid->set_drop_down_table
        EXPORTING
          it_drop_down = lt_dropdown.ENDFORM.                               " dropdown_table
    *&      Form  build_layout
          text
    *layout for ALV output
    FORM build_layout .  gs_layout-cwidth_opt = 'X'.
      gs_layout-grid_title = 'ALV DROPDOWN LISTS'.
      gs_layout-no_toolbar = 'X'.ENDFORM.                    " build_layout
    endform.
    Edited by: S.r.v.r.Kumar on Jun 1, 2009 2:48 PM

  • Multiple selection of rows in alv output list

    experts,
    using 'REUSE_ALV_GRID_DISPLAY'
    the following is the sample code ,without using ctrl or shift key i am unable to select multiple rows .
    any resolvable answers.
    REPORT zpushbutton1.
    type-pools : slis.
    *structure declarations
    types : begin of ty_mara,
    matnr type matnr,
    ernam type ernam,
    mbrsh type mbrsh,
    CHKBOX TYPE CHAR1,
    end oF ty_mara.
    types : begin of ty_marc,
    matnr type matnr,
    werks type werks_d,
    pstat type pstat_d,
    end of ty_marc.
    *internal table declarations
    DATA : gi_mara TYPE STANDARD TABLE OF TY_MARA INITIAL SIZE 0.
    data : gi_fieldcat type slis_t_fieldcat_alv.
    *workarea declarations
    DATA : gs_mara TYPE TY_MARA,
    gs_fieldcat type slis_fieldcat_alv.
    SELECT matnr
    ernam
    mbrsh
    FROM mara
    INTO TABLE gi_mara
    UP TO 10 ROWS.
    perform build_fieldcat using :
    '1' 'CHKBOX' 'GI_MARA' 'SELECT' 'X' ,
    '2' 'MATNR' 'GI_MARA' 'MATEIRALNO' ' ',
    '3' 'ERNAM' 'GI_MARA' 'PERSON CREAT' ' ',
    '4' 'MBRSH' 'GI_MARA' 'INDUSTRY' ' '.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = SY-REPID
    IT_FIELDCAT = GI_FIELDCAT
    TABLES
    t_outtab = GI_MARA
    *& Form BUILD_FIELDCAT
    form BUILD_FIELDCAT using
    PCOL TYPE CHAR2
    PFLDNAME TYPE CHAR10
    PTABNAME TYPE CHAR10
    PSELTEXT TYPE CHAR15
    PINPUT TYPE CHAR1.
    GS_FIELDCAT-COL_POS = PCOL.
    GS_FIELDCAT-FIELDNAME = PFLDNAME.
    GS_FIELDCAT-TABNAME = PTABNAME.
    GS_FIELDCAT-SELTEXT_M = PSELTEXT.
    GS_FIELDCAT-EDIT = PINPUT.
    APPEND GS_FIELDCAT TO GI_FIELDCAT.
    CLEAR GS_FIELDCAT.
    endform. " BUILD_FIELDCAT
    thanks and regards

    experts,
    can we set cursor properties during the output display
    ex : i have used function module reuse_alv_grid_display to display a list of records with passing parameter
    is_layout-box_fieldname and is_layout-box_tabname to list the first column as pushbutton.
    when i select a row ,gets selected now when i move the
    cursor (mouse) to the other row and select the row, the row previously selected will be deselected.
      solution to the above problem is to hold the ctrl or shift key for
    multiple selections.
    is there any other alternative procedure so that without holding
    ctrl or shift key multiple rows get selected.
    thks and rgrds

  • Multiple selection of rows in table

    HI,
    can any one tell how to dispaly the rows selected(multiple selection) in one table can be displayed in another table in  2nd  view.
    Regards,
    A.K

    Hi,
    1.Iterate through the node bound to the table
    2 Add the selected elements to a List.
    3.bind this list to a node
    4.Bind this node as the datasource for the second table.
    Ex:
    ArrayList selectedElements = new ArrayList();
    for (int x=0; x< wdContext.nodeTest().size(); x++)
         if( wdContext.nodeTest().isMultiSelected(x) )
    // Selected Element
    IWDNodeElement nodeElement = wdContext.nodeTest().getElementAt(x);
    selectedElements.add(nodeElement)
    wdContext.nodeSeondNode().bind(selectedElements);
    Regards
    Ayyapparaj

  • Multiple selection of rows and delete the same

    hi how can we select the multiple rows in a table and delete the same.
    if i have 3 rows i have to select 2 rows and if i press the delete button the selected rows should be deleted.
    Can any one help me .
    Thanks
    Badri

    hi
    in the layout of the screen u might have dragged and dropped the table control
    double click on it u will get attributes screen in that u select MULTIPLE under Line-Selection
    under attributes tab.
    the internal table in table control must be like
    data : begin of itab occurs 0,
             empno type .......,
             empname......,
             empcity.....,
             check(1), " for tab selection"
             end of itab.
    data : itab1 like itab occurs 0 with header line.
    in the attributes screen of the table control
    pass the value ITAB-CHECK to the field W/SELECTION
    in SE51
    PBO
    Module_status_0800
    loop with control table_control_name.
    module_fill_tcontrol.
    endloop.
    PAI
    Module_user_command_0800
    loop with control table_control_name.
    module_read_tcontrol.
    endloop.
    in se38
    Module_fill_tcontrol. 
    endmodule.
    Module_read_tcontrol.
    READ TABLE itab1 INDEX control-current_line.
      IF sy-subrc EQ 0.
        MODIFY itab1 FROM itab  INDEX control-current_line.
      ELSE.
        MOVE-CORRESPONDING itab TO itab1.
        APPEND itab1.
        CLEAR itab1.
      ENDIF.
    endmodule.
    module_user_command.
    case sy-ucomm.
    WHEN 'DELE'.
          DELETE itab1 WHERE check = 'X'.
    endcase.
    endmodule.
    Regards
    Murali.M

  • Select whole row in a JTable

    I would like to know how I can fix so that when a user clicks a cell in my JTable the whole row gets selected. Not with the clicked cell as white and the rest of the row in blue, but with the whole row in blue. I would also like to stop the cell from beeing edited. The third thing I wonder is how I can hide the grid between the cells, and make it look like a list??
    Thanks for replies!

    Thanks for the help!
    I managed to get the frame around the selected cell also. Did it by extending the DefaultTableCellRenderer. Found some more help here:
    http://forum.java.sun.com/thread.jsp?thread=447758&forum=57&message=2028189

  • Multiple selection in rows

    Hi,
    How to select multiple rows in marketing documents?
    In the 'List of windows' it is possible but in sales order/Purchase order is it system design or is there any method by which i can achieve this?
    Thanks
    Md.nazeer Shaikh

    Hi Nazeer,
    multiple rows selection is not possible in marketing document but you can achive it through sdk as per requirment.
    Regards.
    Deepak Tyagi

  • How to Select  a Row in a JTable, on a right mouse click?

    Hi all!
    I need to know the Row index in a JTable, on a right mouse click?
    Executing following code, I get the "Column Number" on a mouse click
    TableColumnModel columnModel = tableView.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int columnIdx = tableView.convertColumnIndexToModel(viewColumn);
    Dows any body know the code that gets "rowIdx" on a mouse e.getY() method??
    Hope early response!

    int row = table.rowAtPoint( e.getPoint() );
    int column = table.columnAtPoint( e.getPoint() );

  • How to select a row in a JTable

    I want the following to happen: depending on the value of a variable, i have to change the background color and font of one row. Has anyone an idea how to do that?
    Thx

    check out http://www.globalleafs.com 's download section. There are many programmes out there in java.

  • How to select more than one row in a JTable swing adf adf?

    how to select more than one row in a JTable swing adf adf?

    // Allow selection to span one contiguous set of rows, visible columns, or block of cells
    table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    // Allow multiple selections of rows, visible columns, or cell blocks
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

  • To get the unique id of the selected row in a JTable as in Database

    Hi,
    After fetching the recodrs from the Database, I have displayed them in a JTable. Though I fetched all the columns from db, I am displying only only 2 columns, say Name and Number neither of which is unique, however I have a unique ID for each record in the db. Now when I select some row in the JTable, I need to know its unique ID (the one which is in the db) which i have not displayed in the JTable.
    Is there any API method that can store the unique ids of a table? Or how can this be done?
    Thanks in Advance.

    Although, if you don't want the Id visible in the table, then you need to remove its TableColumn from the TableColumnModel.
    Then when you want to reference the id you need to use:
    table.getModel.getValueAt(...);

  • How to select a row in JTable

    Hello,
    I have a problem selecting a row in a JTable.
    I use
    mytable.getSelectionModel().setSelectionInterval(row, row);
    to select a row, but after that this row is only highlighted. After calling this method I cannot change the selection using the arrow keys.
    Can anybody give me a hint, how I can get the row selected, so that I can use the arrow keys immediately after selecting the row?
    Any help is welcome.
    Thanks,
    Fritz

    Hello,
    I got the solution:
    final int pRow = row;
    final int pCol = column;
    final JTable myTable = mytable;
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    myTable.requestFocusInWindow();
    myTable.changeSelection(pRow, pCol, true, true);

  • Select multiple rows on a JTable

    Hi!
    Given: JTable, multiple selection allowed
    Wanted: a way to be able to set multiple non-continuous rows selected
    eg. on a JTable with 5 rows,
    I want to set rows 1, 3 and 5 selected
    Anyone?
    Stoffel.

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTE
    VAL_SELECTION);
    select rows using <ctrl> and/or <shift>Or if you want to set programaticly use this methods, see the api
    for explanation.
    table.changeSelecton(int row, int column, boolean toogle, boolean extend);
    table.addRowSelection(int index0, int index1);
    table.addColumnSelectionInterval(int index0, int index1)
    ...

  • JTable Multiple Selection

    Hi,
    I am having a problem with the jTable's multiple selection.
    I apply cell renderers on a table's cells and also apply cell selection model on the table. I want to have mutliple row selection but I only get single selection.
    Could someone please explain why that is?
    Thanks
    Zweli
    <code>
    Utils.setupTableColumns(tblLookupProducts);
    Utils.setTableCellRenderer(tblLookupProducts, new CellToolTipRenderer(), -1);
    Utils.setCellFormatRenderer(tblLookupProducts, 5);
    Utils.setCellFormatRenderer(tblLookupProducts, 6);
    tblLookupProducts.setRowSelectionAllowed(true);
    cellSelectionModel = tblLookupProducts.getSelectionModel();
    cellSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    public class CellToolTipRenderer extends DefaultTableCellRenderer {
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int col) {
    Component comp = super.getTableCellRendererComponent(
    table, value, isSelected, hasFocus, row, col);
    comp.setForeground(Color.black);
    comp.setBackground(Color.white);
    if (table.getSelectedRow() == row) {
    comp.setBackground(table.getSelectionBackground());
    comp.setForeground(Color.WHITE);
    setToolTipText(table.getModel().getValueAt(row, col).toString());
    return comp;
    * @author Zweli
    public class CellAlignmentRenderer extends DefaultTableCellRenderer {
    private int column;
    private NumberFormat currency = NumberFormat.getNumberInstance();
    private DecimalFormat df = new DecimalFormat("#,###,###,##0.00");
    private BigDecimal bd;
    public CellAlignmentRenderer(int column) {
    this.column = column;
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int col) {
    Component comp = super.getTableCellRendererComponent(
    table, value, isSelected, hasFocus, row, col);
    comp.setForeground(Color.black);
    comp.setBackground(Color.white);
    if (table.getSelectedRow() == row) {
    comp.setBackground(table.getSelectionBackground());
    comp.setForeground(Color.WHITE);
    if (row != -1) {
    setHorizontalAlignment(SwingConstants.RIGHT);
    setToolTipText(table.getModel().getValueAt(row, col).toString());
    return comp;
    </code>

    Hello,
    Please edit your post and use proper tags.
    +if (table.getSelectedRow() == row) {+
    From the JTable API Javadoc:
    getSelectedRow()
    Returns the index of the first selected row, -1 if no row is selected.
    So this only returns +one+ index among all those selected.
    You could use <tt>getSelectedRows()</tt> (notice the +s+ !) instead, but there's a much better approach: guess what the +isSelected+ argument to <tt>getTableCellRendererComponent(...)</tt> stands for :o)
    Regards.
        J.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for