TableUI implementation to distinguish editable/noneditable cells

I have implemented a Look and Feel for a swing application that changes the background of text fields, combo boxes, check boxes, etc to the standard editable color (typically a white color) when they are enabled. When the field is diabled, the color is made to be that of the button background color (typically a lightgray color). In the tables, the default color for a cell is white (editable or not). I have found a solution for updating the cell renderers that makes the color scheme standard across the application, but I would like to continue with the look&feel approach using a tableUI. I have created a tableUI class that implements the paint method. This method is a variation of the method decompiled from the BasicTableUI implementation (my source code will follow). I am still having a few problems with painting. The first row in the table, the first time the table is painted, still shows up with the standard colors until clicked on, sorted, column dragged, focus lost and gained, etc. - basically anything that forces the table to paint again. I fixed this by calling the paintCells method twice, but I do not like this(for obvious reasones) and do not fully understand the problem. Furthermore, I have noticed that in some tables that have rows with different columns disabled than others, clicking from row to row can cause paint flickering, where the control starts out white and then goes gray. I have yet to see any examples of anyone trying to solve swing's inconsistency with the check boxes, textfields, textarea, dropdowns, and tables. Any help would be appreciated.
     public void paint(Graphics graphics, JComponent jcomponent) {
          if (table.getRowCount() > 0 && table.getColumnCount() > 0) {
               Rectangle rectangle = graphics.getClipBounds();
               Point point = rectangle.getLocation();
               Point diagPoint = new Point(rectangle.x + rectangle.width - 1,
                            rectangle.y + rectangle.height - 1);
               int topRow = table.rowAtPoint(point);
               int bottomRow = table.rowAtPoint(diagPoint);
               if (topRow == -1) topRow = 0;
               if (bottomRow == -1) bottomRow = table.getRowCount() - 1;
               int leftCol = table.columnAtPoint(point);
               int rightCol = table.columnAtPoint(diagPoint);
               if (leftCol == -1) leftCol = 0;
               if (rightCol == -1) rightCol = table.getColumnCount() - 1;
               paintGrid(graphics, topRow, bottomRow, leftCol, rightCol);
               paintCells(graphics, topRow, bottomRow, leftCol, rightCol);
               //added re-call because first line of table was not painting
                        //correct table on first render of the table
               paintCells(graphics, topRow, bottomRow, leftCol, rightCol);
     private void paintCells(Graphics graphics, int topRow, int bottomRow,
                int leftCol, int rightCol) {
          JTableHeader jtableheader = table.getTableHeader();
          TableColumn tablecolumn = jtableheader == null ? null : jtableheader.getDraggedColumn();
          TableColumnModel tablecolumnmodel = table.getColumnModel();
          int colMargin = tablecolumnmodel.getColumnMargin();
          for (int i = topRow; i <= bottomRow; i++) {
               Rectangle rectangle = table.getCellRect(i, leftCol, false);
               for (int j = leftCol; j <= rightCol; j++) {
                    TableColumn column = tablecolumnmodel.getColumn(j);
                    int colWidth = column.getWidth();
                    rectangle.width = colWidth - colMargin;
                    if (column != tablecolumn) paintCell(graphics, rectangle, i, j);
                    rectangle.x += colWidth;
          if (tablecolumn != null)
               paintDraggedArea(graphics, topRow, bottomRow,
                           tablecolumn, jtableheader.getDraggedDistance());
          rendererPane.removeAll();
     private void paintCell(Graphics graphics, Rectangle rectangle, int row, int col) {
          boolean enabled = table.isCellEditable(row, col) && table.isEnabled();
          if (table.isEditing() && table.getEditingRow() == row && table.getEditingColumn() == col) {
               Component component = table.getEditorComponent();
               component.setBounds(rectangle);
               component.validate();
          } else {
               TableCellRenderer tablecellrenderer = table.getCellRenderer(row, col);
               Component component = table.prepareRenderer(tablecellrenderer, row, col);
               boolean selected = table.getSelectedRow() == row;
               if (enabled) {
                    if (selected) {
                         Color bckgrnd = (Color)UIManager.get("Table.selectionBackground");
                         int red = ((bckgrnd.getRed() + 36) >= 255
                                            ? 255 : bckgrnd.getRed() + 36);
                         int green = ((bckgrnd.getGreen() + 36) >= 255
                                            ? 255 : bckgrnd.getGreen() + 36);
                         int blue = ((bckgrnd.getBlue() + 36) >= 255
                                            ? 255 : bckgrnd.getBlue() + 36);
                         bckgrnd = new Color(red, green , blue);
                         component.setBackground(bckgrnd);
                    } else {
                         component.setBackground((Color)UIManager.get("Table.background"));
               } else {
                    if (selected)
                         component.setBackground((Color)UIManager.get(
                                            "Table.selectionBackground"));
                    else
                         component.setBackground((Color)UIManager.get("Label.background"));
               rendererPane.paintComponent(graphics, component, table, rectangle.x,
                            rectangle.y, rectangle.width, rectangle.height, true);
     }

The best way to do this is with a custom table cell renderer. Renderer's are passed all the params about the cell (including if it's editable). You just set the background (or whatever) of your rendering component based on that flag and return it. It is very easy to extend the existing default renderers for this, as well as to create your own custom ones.
Doing this via a custom UI really isn't practical because everyone that creates a custom renderer has the ability to draw the cell themselves ignoring whatever nifty 'work' your UI may be doing.

Similar Messages

  • Editing in cell

    i just switched from pc/excel to mac/Numbers, and i can't figure out how to (a) change my preferences so that the cursor doesn't move down a cell after i press return and (b) edit in cell. in excel and lotus, you pressed f2 to edit in cell (and to switch between editing in cell and moving the cursor around the sheet); in Numbers i can't find that option.

    Hi dre1973,
    Welcome to Numbers forum.
    1. Regarding the cursor movement: Enter or Return moves it down Tab moves it to the right. As in other programs there isn't any way to make a change.
    2. In cell editing: double click on the cell.
    If those answers are not satisfactory please contact Numbers development team: At the top of the screen to the right of the blue apple click Numbers > Provide Numbers Feedback. Your request goes directly to the Numbers team. Then hope your request is implemented in the next version of Numbers.
    Because of different design philosophies MS and Apple do things differently, neither is incorrect.
    Sincerely,
    RicD

  • Default behaviour of the Escape key while editing a cell in JTable??

    Hi all,
    i have a Jtable which get its data from an own model object which extends DefaultTableModel.
    If i overwrite the isCellEditable(row, col) method within the tablemodel object and set a specific column to editable, then i notice while editing a cell in that column that the default behaviour of the Escape key is that independet from what you have entered before in to the cell the editing stops and the cell gets the value it had before editing.
    This is the case for me even if i apply a custom editor to a column (one that extends DefaultCellEditor). It is just a JTextField that limits the number of digits a user can enter. Everything works fine. If the user edits the cell and presses ENTER or the "down arrow key" i can check what he has entered with the help of the getCellEditorValue() method. But if the user hits the ESC key after editing a cell this method is not invoked!!!
    My question is :
    is there any way to detect that the user cancels editing with the ESC-key.
    this is very important for me because if the user goes editing the cell i lock the related record in the database, if i cannot detect this it is locked till the application terminates.
    Thanks for any help in advance

    I try override the JTable editingCanceled() ==> does not work.
    I try the addCellEditorListener( CellEditorListener l ) ==> does not work.
    Finally, I try the addKeyListener ==> it works.
    Here is a quick demo. program:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class Test {
    public static void main(String[] args){
    JFrame f = new JFrame();
    String[] colName = {"a", "b"};
    String[][] rowData = {{"1", "2"}, {"3", "4"}};
    JTable table = new JTable(rowData, colName);
    JTextField t = new JTextField(10);
    t.setBackground(Color.red);
    t.addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
    // do what ever you want ex. un-lock table
    System.out.println("ESCAPE");
    DefaultCellEditor editor = new DefaultCellEditor(t);
    TableColumnModel colModel = table.getColumnModel();
    for (int i = colModel.getColumnCount()-1; i >= 0; i--) {
    colModel.getColumn(i).setCellEditor(editor);
    f.setContentPane(new JScrollPane(table));
    f.pack();
    f.setVisible(true);

  • Help with editing a cell in a JTable. DESPERATE

    Hi! Is there someone out there that could help with some source code for editing a cell in my JTable when I run it as an applet??
    It works fine when I run it as an application.
    I manage to select the row and write a number in it, but I can't get out of the cell (it seems that the program stops??). I want to enter an integer in a cell and when I click enter or with the mouse in an other cell the value that I enter should update some other cell( multiply the entered value with some fixed number and update a cell in a second coloumn)
    I am really desperate now..... I have thought about using a MouseListener....
    I am using a tablemodel that is from AbstractTableModel.

    Are you using some cell editors?
    While converting inside them, you might be getting some exceptions (like parseexception)which is stopping you from proceeding further.
    Are you using your own tablemodel with custom datatypes?
    Hope this helps,
    Ramkumar

  • Dynamically Rendering and editing JTable cell

    Hi all,
    I wonder if some body can help me.
    As in my application each cell in Jtable returns java Object. and what i am trying to do is based on each object returned in cell my renderer is going to change dynamically. for example if the object returned is primitive data types the renderer is defualt, if the returned object is Map, Set or List, then the Cell Renderer should show clickable button with icon on right hand side and TextField on left hand side and so on for other objects. i am able get renderer for Map, set or list, which is button on right hand side of cell and text field on left hand side displaying toString of Object. then what i want is when i click button it should show those values in popup window and if i double click it should edit the cell which i am able to do it. so how can i handle events or what i have to do to make button clickable. if any body come accross these situations or got idea. please let me know how to move further.
    Thanks,
    Kotesh.

    Hi,
    Thanks for your advise and as i said i am able to get render for Map as (TextField in left hand side+Button with icon in right hand side side) of Cell. but what i need is when i click button which is on right hand, then i should be able to show popup wvindow with map values and if i double click on TextField which is on right hand side, then i should be able to edit Cell which is happening. but i am not able to get popup window when i click button on right hand side of cell. basically i am not sure how to handle events on cell and the button on right hand side?
    if some one can guide me that will be great as i am in big trouble.
    Thanks
    Kotesh.

  • Theme Editor: where to change backgroundcolor of editable table cells?

    Hi all,
    I need to change the color of an editable table cell.
    I navigated to the theme editor --> tables.There is a section "Editable Tables". The preview shows an example with three columns and tree rows. I want to change the backgroundcolor of the cell in the first row, third column (in SAP standard it is lightgrey).
    The backgroundcolor of the rows beneath can be changed in section "Selected Cells", the backgroundcolor of the first two columns in the first row can be changed by "Background Color of Standard Table Cell" but I can't find the field where I can change the color of the last cell.
    Best regards,
    Sandra

    Hi,
    The blue color come from your definitions on "Labels and Fields" to read-only color of input field.
    Regards,
    F.F

  • Edit table cells

    i have edited the setValueAt method of the TableModel interface to enable editing of cells in my JTable - in-situ. This works fine. However, i would like it so that when any change is made to the table data, it is automatically sorted depending on how it was sorted before the change was made. i have:
    public void setValueAt(Object aValue, int row, int col) {
            if (col == 0) {
                bookList[row].setBookNumber(Integer.parseInt((String)aValue)); // Populates cell with new book number
                if (lastSort == "number") {
                    listByNumber();
            } else {
                if (col == 1) {
                    bookList[row].setTitle((String)aValue); // Populates cell with new book title
                } else {
                    if (col == 2) {
                        bookList[row].setAuthorPrename((String)aValue); // Populates cell with new author prename
                    } else {
                        bookList[row].setAuthorSurname((String)aValue); // Populates cell with new author surname
        }i would put more if statements in later for different sort methods but at the moment ill just stick with one. My problem is that the array is being sorted correctly, but the table doesn't update automatically to show the change. what DOES happen - is when you click on each row of the table, it changes until it is in the correct order. this leads me to think that the sorting works fine, but somehow my table model isnt reflecting the changes? can any help me update the table in real time?

    no luck :( i tried:
       public void setValueAt(Object aValue, int row, int col) {
            if (col == 0) {
                bookList[row].setBookNumber(Integer.parseInt((String)aValue)); // Populates cell with new book number  
                listByNumber();
                fireTableDataChanged();and extended AstractTableModel but it still didnt work. is there anything else i would need to do?

  • HTMLB TableView Iterator & Edit columns, cells

    Hi friends,
    I am getting errors when , I tried to edit the columns, & Cells of  HTMLB TableView by using Iterator.Actually, I got the whole edit buttons and when I edit the values of particular column & cell fileds, it is not saving the values, instead it is giving same old values. The code I used is as follows.
    <u><b>To Edit the  columns,</b></u>
    method
    IF_HTMLB_TABLEVIEW_ITERATOR~GET_COLUMN_DEFINITIONS.
    FIELD-SYMBOLS: <def> LIKE LINE OF p_column_definitions.
      APPEND INITIAL LINE TO p_column_definitions ASSIGNING <def>.
    <def>-COLUMNNAME = 'STUDENTID'.<def>-EDIT = 'X'.
    endmethod.
    <u><b>To Edit the  cells,</b></u>
    RENDER_CELL_START Method:
    method
    IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START.
    CASE p_column_key.
    WHEN 'ICON'.
    WHEN 'STUDENTID'.
           IF p_edit_mode IS NOT INITIAL.
    ENDIF.
    WHEN 'SDATE'.
           IF p_edit_mode IS NOT INITIAL.
    ENDIF.
    ENDCASE.
    endmethod.
    <u><b>To Edit the SDATE cells,</b></u>
    WHEN 'SDATE'.
      IF p_edit_mode IS NOT INITIAL.
    DATA: date TYPE STRING.
    date = m_row_ref->SDATE.
    p_replacement_bee = CL_HTMLB_INPUTFIELD=>FACTORY(
                          id        = p_cell_id
                           value     = date
                           type      = 'DATE'
                             showHelp  = 'TRUE'
                             cellValue = 'TRUE' ).
                               ENDIF.
    Why the either column or cell is not saving the new values, when I edit them? where it went wrong? please mail me in this regard.
    regards
    CSM Reddy

    Hi REDDY CSM 
    To learn coding these Methods.
    You need to learn everything from scratch about MVC.
    To learn functionalities of Methods in Controller and how to use them,its Better,if you start with some tutorial(Little application) on MVC.
    Here is link,Just follow this,You will get some Exposure to these methods.
    http://help.sap.com/saphelp_erp2005/helpdata/en/c8/101c3a1cf1c54be10000000a114084/frameset.htm
    Rest keep posting whenever you face and Problem..
    Happy Coding..!!
    Vijay Raheja

  • When using macbook air and excel, what is the shortcut to edit a cell

    when I want to edit a cell, i know that I can point to the cell and click; but is there anything like function f2 that would be shortcut ?

    You still have to point to the cell to edit.  A double tap on the trackpad will allow an "in cell" edit of the formula. (If you have tap to click enabled in preferences)
    Captfred

  • Programmatically Editing a Cell Not Working

    Hi Guys,
    I'm trying to automatically begin editing a cell within a JTable as soon as the table is displayed.
    I've tried using the table.editCellAt(int row, int col) method but it just seems to have no effect.
    I've set the cell editable within my custom table class (and I know it is because if I double click on the cell or type anything then the editor is displayed).
    FYI I'm using Java 1.5
    Anyone got any ideas?

    Does nobody know how to automatically engage the editor component of a JTable programatically i.e. without having to click on the cell?? The code I gave you above works fine for me in JDK1.4.2. Why don't you post the 10 line demo program you are using to test my suggestion. That way people can determine whether you test code is wrong or 1.5 isn't working.

  • Edit two cells at the same time

    Hi friends!
    Is it possible to edit two cells of JTable at the same time?
    When I click on a cell, the cell enters in edit mode, but I want to edit another cell at the same time. To do that I use this method :
    GrelhaHorarios.editCellAt(row,col);The problem is the other cell returns to the rendered form and only one is in edit mode. Regard that I don't to want introduce values manually, but with the setValueAt(...) method.
    Thanks in advance.

    You can only edit a single cell at a time.
    You do not need to place a cell in edit mode to use the setValueAt(...) method.

  • Edit One Cell In Alvs Based On Some Condition

    Hi Experts,
          My Requirement Is  :
    Has To *Edit one cell using alv grid *, for ex: If  Netpr > 100(value). that should be in editable mode,rest of the cells  in non-editable mode. pls let me know how to do it,
    best answer rewarded
    Reagrds,
    Fareedas.

    Hi Fareedas,
    The follow program demonstrates how to make individual fields of an ALV grid editable (NetPR greater than 10). Changes required from a basic ALV grid include adding a new field to ALV grid data table(it_ekko), Populating this field with style attribute and adding an entry to layout control table. Also from the previous examples used on this website you will also need to change the data type of the fieldcatalog, the layout and use a different function module for displaying the report
    *& Report  ZDEMO_ALVGRID_EDIT                                          *
    *& Example of a simple ALV Grid Report                                 *
    *& The basic ALV grid, Enhanced to display specific fields as          *
    *& editable depending on field value                                   *
    REPORT  ZDEMO_ALVGRID_EDIT                 .
    TABLES:     ekko.
    TYPE-POOLS: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
      field_style  TYPE lvc_t_styl, "FOR DISABLE
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.
    DATA: it_fieldcat TYPE lvc_t_fcat,     "slis_t_fieldcat_alv WITH HEADER LINE,
          wa_fieldcat TYPE lvc_s_fcat,
          gd_tab_group TYPE slis_t_sp_group_alv,
          gd_layout    TYPE lvc_s_layo,     "slis_layout_alv,
          gd_repid     LIKE sy-repid.
    *Start-of-selection.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM set_specific_field_attributes.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
    *       Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      wa_fieldcat-fieldname   = 'EBELN'.
      wa_fieldcat-scrtext_m   = 'Purchase Order'.
      wa_fieldcat-col_pos     = 0.
      wa_fieldcat-outputlen   = 10.
      wa_fieldcat-emphasize   = 'X'.
      wa_fieldcat-key         = 'X'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'EBELP'.
      wa_fieldcat-scrtext_m   = 'PO Item'.
      wa_fieldcat-col_pos     = 1.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'STATU'.
      wa_fieldcat-scrtext_m   = 'Status'.
      wa_fieldcat-col_pos     = 2.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'AEDAT'.
      wa_fieldcat-scrtext_m   = 'Item change date'.
      wa_fieldcat-col_pos     = 3.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'MATNR'.
      wa_fieldcat-scrtext_m   = 'Material Number'.
      wa_fieldcat-col_pos     = 4.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'MENGE'.
      wa_fieldcat-scrtext_m   = 'PO quantity'.
      wa_fieldcat-col_pos     = 5.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'MEINS'.
      wa_fieldcat-scrtext_m   = 'Order Unit'.
      wa_fieldcat-col_pos     = 6.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'NETPR'.
      wa_fieldcat-scrtext_m   = 'Net Price'.
      wa_fieldcat-edit        = 'X'. "sets whole column to be editable
      wa_fieldcat-col_pos     = 7.
      wa_fieldcat-outputlen   = 15.
      wa_fieldcat-datatype     = 'CURR'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'PEINH'.
      wa_fieldcat-scrtext_m   = 'Price Unit'.
      wa_fieldcat-col_pos     = 8.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
    *       Build layout for ALV grid report
    FORM build_layout.
    * Set layout field for field attributes(i.e. input/output)
      gd_layout-stylefname = 'FIELD_STYLE'.
      gd_layout-zebra             = 'X'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
    *       Display report using ALV grid
    FORM display_alv_report.
      gd_repid = sy-repid.
    *  call function 'REUSE_ALV_GRID_DISPLAY'
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
           EXPORTING
                i_callback_program      = gd_repid
    *            i_callback_user_command = 'USER_COMMAND'
                is_layout_lvc               = gd_layout
                it_fieldcat_lvc             = it_fieldcat
                i_save                  = 'X'
           TABLES
                t_outtab                = it_ekko
           EXCEPTIONS
                program_error           = 1
                OTHERS                  = 2.
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " DISPLAY_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
    *       Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
       UP TO 10 ROWS
        FROM ekpo
        INTO  CORRESPONDING FIELDS OF TABLE it_ekko.
    ENDFORM.                    " DATA_RETRIEVAL
    *&      Form  set_specific_field_attributes
    *       populate FIELD_STYLE table with specific field attributes
    form set_specific_field_attributes .
      DATA ls_stylerow TYPE lvc_s_styl .
      DATA lt_styletab TYPE lvc_t_styl .
    * Populate style variable (FIELD_STYLE) with style properties
    * The NETPR field/column has been set to editable in the fieldcatalog...
    * The following code sets it to be disabled(display only) if 'NETPR'
    * is gt than 10.
      LOOP AT it_ekko INTO wa_ekko.
        IF wa_ekko-netpr GT 10.
          ls_stylerow-fieldname = 'NETPR' .
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
                                                 "set field to disabled
          APPEND ls_stylerow  TO wa_ekko-field_style.
          MODIFY it_ekko FROM wa_ekko.
        ENDIF.
      ENDLOOP.
    endform.                    " set_specific_field_attributes
    Check the above code.
    For a sample code using ABAP OO check the program BCALV_EDIT_02.
    Hope this helps.
    Rwd points if helpful.
    Thanks,
    Balaji

  • JTable edits wrong cell on mouseclick

    I am using an editable JComboBox as my cell editor. When the user is editing a cell and clicks on another cell with the mouse, the value of the cell they were editing is inserted into the cell that they clicked on. Can anyone please help me. Thanks.

    The Swing tutorial has a working example:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#combobox

  • Activity implementer can not edit Manual activity content

    user role activity implementer can not edit Manual activity content assigned to him
    just he can mark complete or mark as faild
    what is required to give user permission to edit Manual activity ?
    Ahmed

    attached user role tasks assigned, still can not edit Manual activity assigned to him
    Ahmed

  • Help on Editing a Cell in a JTable

    Hi Folks,
    I have a JTable with two Columns and Some number of rows. My Second Column is Editable i.e., I can change the contents of the cell in the same. My Problem is, When I Select the particular cell in Column2 for Editing it starts appending the text I have typed after the text already present in the Selected Cell.Instead I wanted it to overwrite the previous text present in that cell.(Just like the effect we get in MS Excel). Now What I have to do is press F2 and then press CTRL+A to select all the text in the selected Cell and do the editing. This is somewhat a pain in the Ass to do if you have to Edit a huge table. Is there a Solution for the above problem wherein as soon as I select the cell to edit, it should start overwriting on the previous text instead of appending to the same.There are duke dollars in the offing. Anybody interested in helping me out...???
    Thanks in Advance...
    Sachin Shanbhag

    Hi,
    I am using a JTable with cell editor using TableCellEditor.My table consists of two columns of which first one is using JTextField and the second column ( only the for the column of newly added row) using combobox as editors.My requirement is when a cell gets a focus the cell text should be selected automatically (only for the first column which is using JTextField)) with out the user explicitly going to the focused cell and select the text using mouse.
    If anybody can put some idea on this then it would be fine.
    Thanks
    My code is like this.
    public class PurposesTableEditor implements TableCellEditor
              private TableCellEditor editor;
              private TableCellEditor defaultEditor;
              * HashTable variable for storing editors.
              private Hashtable editors;
              * Constructor.
              public PurposesTableEditor()
                   editors = new Hashtable();
                   defaultEditor = new DefaultCellEditor(new JTextField());
              public void add(int row , TableCellEditor editor)
                   editors.put(new Integer(row),editor);
              public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int col)
                   editor = (TableCellEditor)editors.get(new Integer(row));
                   if (editor == null)
                        editor = defaultEditor;
                   return editor.getTableCellEditorComponent(table, value, isSelected, row, col);
              public boolean stopCellEditing()
                   table.getCellRect(table.getSelectedRow(),0,false);
                   table.getCellRect(table.getRowCount()-1, 0, false);
                   return editor.stopCellEditing();
              public void cancelCellEditing()
                   editor.cancelCellEditing();
              public boolean isCellEditable(EventObject anEvent)
                   return true;
              public boolean shouldSelectCell(EventObject anEvent)
                   return editor.shouldSelectCell(anEvent);
              public void addCellEditorListener(CellEditorListener l)
                   editor.addCellEditorListener(l);
              public Object getCellEditorValue()
                   return editor.getCellEditorValue();
              public void removeCellEditorListener(CellEditorListener l)
                   editor.removeCellEditorListener(l);
         }

Maybe you are looking for