Stop cell editing

I am facing bit common problem related to stop cell editing, here is code attached, when i do insert any string on cell and right after that clicking on save button, and i want to stop cell editing of table.
and i know that this is easy to stop cell editing with line of code
table.getCellEditor().stopCellEditing()but my problem is that i don't have access of this table on action performed of button. and that is not possible to access table here on action event. so please suggest me how to call stop cell editing when i move away with table.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class TableEdit extends JFrame
   TableEdit()
      JTable table = new JTable(5, 5);
      table.setPreferredScrollableViewportSize(table.getPreferredSize());
      JScrollPane scrollpane = new JScrollPane(table);
      JPanel panel = new JPanel();
      panel.add(scrollpane);
      //getContentPane().add();
      JButton button = new JButton("Save");
      button.addActionListener(new ActionListener()
         @Override
         public void actionPerformed(ActionEvent e)
            // TODO Auto-generated method stub
      panel.add(button);
      getContentPane().add(panel);
   public static void main(String[] args)
      JFrame frame = new TableEdit();
      frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
}

but my problem is that i don't have access of this table on action performed of button. and that is not possible to access table here on action event. smake 'table' a field instead of local variable.
public class TableEdit extends JFrame
     JTable table = new JTable(5, 5);
     .....Thanks!

Similar Messages

  • Stopping cell editing in a JTable using a JComboBox editor w/ AutoComplete

    Hi there! Me again with more questions!
    I'm trying to figure out the finer parts of JTable navigation and editing controls. It's getting a bit confusing. The main problem I'm trying to solve is how to make a JTable using a combo box editor stop editing by hitting the 'enter' key in the same fashion as a JTextField editor. This is no regular DefaultCellEditor though -- it's one that uses the SwingX AutoCompleteDecorator. I have an SSCCE that demonstrates the issue:
    import java.awt.Component;
    import java.awt.EventQueue;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JTable;
    import javax.swing.WindowConstants;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableModel;
    import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
    public class AutoCompleteCellEditorTest extends JFrame {
      public AutoCompleteCellEditorTest() {
        JTable table = new JTable();
        Object[] items = {"A", "B", "C", "D"};
        TableModel tableModel = new DefaultTableModel(2, 2);
        table.setModel(tableModel);
        table.getColumnModel().getColumn(0).setCellEditor(new ComboCellEditor(items));
        getContentPane().add(table);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        pack();
      private class ComboCellEditor extends AbstractCellEditor implements TableCellEditor {
        private JComboBox comboBox;
        public ComboCellEditor(Object[] items) {
          this.comboBox = new JComboBox(items);
          AutoCompleteDecorator.decorate(this.comboBox);
        public Object getCellEditorValue() {
          return this.comboBox.getSelectedItem();
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
          comboBox.setSelectedItem(value);
          return comboBox;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() {
            new AutoCompleteCellEditorTest().setVisible(true);
    }Problem 1: Starting to 'type' into the AutoCompleteDecorate combo box doesn't cause it to start editing. You have to hit F2, it would appear. I've also noticed this behaviour with other JComboBox editors. Ideally that would be fixed too. Not sure how to do this one.
    Problem 2: After editing has started (say, with the F2 key), you may start typing. If you type one of A, B, C, or D, the item appears. That's all good. Then you try to 'complete' the edit by hitting the 'enter' key... and nothing happens. The 'tab' key works, but it puts you to the next cell. I would like to make the 'enter' key stop editing, and stay in the current cell.
    I found some stuff online suggesting you take the input map of the table and set the Enter key so that it does the same thing as tab. Even though that's not exactly what I desired (I wanted the same cell to be active), it didn't work anyway.
    I also tried setting a property on the JComboBox that says that it's a table cell editor combo box (just like the DefaultCellEditor), but that didn't work either. I think the reason that fails is because the AutoCompleteDecorator sets isEditable to true, and that seems to stop the enter key from doing anything.
    After tracing endless paths through processKeyBindings calls, I'm not sure I'm any closer to a solution. I feel like this should be a fairly straightforward thing but I'm having a fair amount of difficulty with it.
    Thanks for any direction you can provide!

    Hi Jeanette,
    Thanks for your advice. I looked again at the DefaultCellEditor. You are correct that I am not firing messages for fireEditingStopped() and fireEditingCancelled(). Initially I had copied the behaviour from DefaultCellEditor but had trimmed it out. I assumed that since I was extending AbstractCellEditor and it has them implemented correctly that I was OK. But I guess that's not the case! The problem I'm having with implementing the Enter key stopping the editing is that:
    1) The DefaultCellEditor stops cell editing on any actionPerformed. Based on my tests, actionPerformed gets called whenever a single key gets pressed. I don't want to end the editing on the AutoCompleteDecorated box immediately -- I'd like to wait until the user is happy with his or her selection and has hit 'Enter' before ending cell editing. Thus, ending cell editing within the actionPerformed listener on the JComboBox (or JXComboBox, as I've made it now) will not work. As soon as you type a single key, if it is valid, the editing ends immediately.
    2) I tried to add a key listener to the combo box to pick up on the 'Enter' key and end the editing there. However, it appears that the combo box does not receive the key strokes. I guess they're going to the AutoCompleteDecorator and being consumed there so the combo box does not receive them. If I could pick up on the 'Enter' key there, then that would work too.
    I did more reading about input maps and action maps last night. Although informative, I'm not sure how far it got me with this problem because if the text field in the AutoCompleteDecorator takes the keystroke, I'm not sure how I'm going to find out about it in the combo box.
    By the way, when you said 'They are fixed... in a recent version of SwingX', does that mean 1.6.2? That's what I'm using.
    Thanks!
    P.S. - Maybe I should create a new question for this? I wanted to mark your answer as helpful but I already closed the thread by marking the answer to the first part as correct. Sorry!
    Edited by: aardvarkk on Jan 27, 2011 7:41 AM - Added SwingX versioning question.

  • JTree stop cell editing on lost focus and scrollPathToVIsible behavior

    how can you make a Jtree that uses a DefaultTreeCellEditor stop editing when it loses focus to a component other than the
    cell editor's DefaultTextField component ?
    i had to use a custom TreeCellEditor and attach my focus listener to the DefaultTextField object and attach it also to the JTree object
              DefaultTreeCellEditor celEditor = new DefaultTreeCellEditor(containerTree,renderer)
                   @Override
                   public Component getTreeCellEditorComponent(JTree tree, Object value,
                                     boolean isSelected,
                             boolean expanded,
                             boolean leaf, int row) {
                        Component comp = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
                        boolean found= false;
                        for(FocusListener f:editingComponent.getFocusListeners())
                             if(focusListener.equals(f))
                                  found=true;
                                  break;
                        if(!found)
                             editingComponent.addFocusListener(focusListener);
                        return comp;
    myTree.addFocusListener(focusListener);in JTable there's a property that you switch on/off which does exactly that, is there anything alike for JTree ?
    one more thing,after adding a new TreeNode to the JTree,i'm calling scrollPathToVisible(<path to the new node>),but for all the nodes i add except the first, the user object is not displayed,am i missing something? here's my code
              ActionListener actionListener = new ActionListener(){
                   public void actionPerformed(ActionEvent ae){
                        DefaultTreeModel model = (DefaultTreeModel)containerTree.getModel();
                        int nodeCount=containerTree.getModel().getChildCount(root);
                        if(ae.getSource().equals(menuAdd))
                             DefaultMutableTreeNode newNode=new DefaultMutableTreeNode();
                             if(currentNode>0 && currentNode+1<nodeCount)
                                  model.insertNodeInto(newNode, root, currentNode+1);
                                  newNode.setUserObject("container #"+(currentNode+1));
                             else
                                  model.insertNodeInto(newNode, root, root.getChildCount());
                                  newNode.setUserObject("container #"+nodeCount);
                             TreePath path = new TreePath(newNode.getPath());
                                            // only works properly for 1st node,for the rest i have to
                                            // click on the new node to get the proper display
                             containerTree.scrollPathToVisible(path);
                        else if(nodeCount>=0 && currentNode!=0)
                             model.removeNodeFromParent((DefaultMutableTreeNode)model.getChild(root, currentNode-1));
              };

    i solved the second issue by selecting the new node and starting to edit it

  • Cell editing stopCellEditing

    Greetings
    If I understand the sequence of events when cell editing takes place, if one is using a custom cell editor and has overridden the stopCellEditing method, this would be the place to perform input validation - if a value is unacceptable the method would return false, indicating to the component that editing should not be stopped. Is it possible for this method to know exactly which cell is being edited (row #, column #) ?
    Thanks,
    Oscar Hobson

    The one who's dense is probably me, and unfortunately I don't know that much about JTables yet... But from what I've seen, I think the celleditor doesn't know about any other cells (or tables) but the one it's editing.
    Your validation could be done in the component that the celleditor uses, or if your celleditor extends DefaultCellEditor, you could do the checking in getCellEditorValue().
    stopCellEditing() is called with action events like button click etc. In the handling of the action event you could check whether the table is still editing and then call the editor's stopCellEditing() when necessary. There you would have access to the indexes as explained before.
    If you do a search on this forum, you might run into some more detailed explanations of validating etc. that could be more precisely what you are looking for.
    Regards,
    Zarco

  • How can i make perticular row or perticular cell Editable  of a JTable

    Dear al,
    can u help me by guiding me for the problem of...
    i am having a JTable, in which a (first)column of each row is having a checkbox field.
    If the checkbox is checked then and then i should able to modify the cells in that row where the checkbox is.
    I have created the table with AbstractTableModel of which the isCellEditable(int row, int col) method is overwriten. Whatever return value (true/false) reflects the perticular
    cells becomes editable/non-editable respectively.
    but at run time...(mean the table is created now) and now i want to make the cells editable/non-editable depending on the checkbox value...
    how can i implement it.........
    please suggest.........
    thank you.........

    here is the sample code from tutorial.......
    * TableRenderDemo.java requires no other files.
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    * TableRenderDemo is just like TableDemo, except that it explicitly initializes
    * column sizes and it uses a combo box as an editor for the Sport column.
    @SuppressWarnings("serial")
    public class TableRenderDemo extends JPanel {
         private boolean DEBUG = true;
         public TableRenderDemo() {
              super(new GridLayout(1, 0));
              JTable table = new JTable(new MyTableModel());
              // table.setEditingColumn(0);
              // table.editCellAt(0, 0);
              table.setPreferredScrollableViewportSize(new Dimension(500, 100));
              // Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              // Set up column sizes.
              initColumnSizes(table);
              // Fiddle with the Sport column's cell editors/renderers.
              setUpSportColumn(table, table.getColumnModel().getColumn(2));
              // Add the scroll pane to this panel.
              add(scrollPane);
          * This method picks good column sizes. If all column heads are wider than
          * the column's cells' contents, then you can just use
          * column.sizeWidthToFit().
         private void initColumnSizes(JTable table) {
              MyTableModel model = (MyTableModel) table.getModel();
              TableColumn column = null;
              Component comp = null;
              int headerWidth = 0;
              int cellWidth = 0;
              Object[] longValues = model.longValues;
              TableCellRenderer headerRenderer = table.getTableHeader()
                        .getDefaultRenderer();
              for (int i = 0; i < 5; i++) {
                   column = table.getColumnModel().getColumn(i);
                   comp = headerRenderer.getTableCellRendererComponent(null, column
                             .getHeaderValue(), false, false, 0, 0);
                   headerWidth = comp.getPreferredSize().width;
                   comp = table.getDefaultRenderer(model.getColumnClass(i))
                             .getTableCellRendererComponent(table, longValues, false,
                                       false, 0, i);
                   cellWidth = comp.getPreferredSize().width;
                   if (DEBUG) {
                        System.out.println("Initializing width of column " + i + ". "
                                  + "headerWidth = " + headerWidth + "; cellWidth = "
                                  + cellWidth);
                   // XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
                   column.setPreferredWidth(Math.max(headerWidth, cellWidth));
         public void setUpSportColumn(JTable table, TableColumn sportColumn) {
              // Set up the editor for the sport cells.
              JComboBox comboBox = new JComboBox();
              comboBox.addItem("Snowboarding");
              comboBox.addItem("Rowing");
              comboBox.addItem("Knitting");
              comboBox.addItem("Speed reading");
              comboBox.addItem("Pool");
              comboBox.addItem("None of the above");
              sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
              // Set up tool tips for the sport cells.
              DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
              renderer.setToolTipText("Click for combo box");
              sportColumn.setCellRenderer(renderer);
         class MyTableModel extends AbstractTableModel {
              private String[] columnNames = { "First Name", "Last Name", "Sport",
                        "# of Years", "Vegetarian" };
              private Object[][] data = {
                        { "Mary", "Campione", "Snowboarding", new Integer(5),
                                  new Boolean(false) },
                        { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) },
                        { "Kathy", "Walrath", "Knitting", new Integer(2),
                                  new Boolean(false) },
                        { "Sharon", "Zakhour", "Speed reading", new Integer(20),
                                  new Boolean(true) },
                        { "Philip", "Milne", "Pool", new Integer(10),
                                  new Boolean(false) } };
              public final Object[] longValues = { "Sharon", "Campione",
                        "None of the above", new Integer(20), Boolean.TRUE };
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return data.length;
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   return data[row][col];
              * JTable uses this method to determine the default renderer/ editor for
              * each cell. If we didn't implement this method, then the last column
              * would contain text ("true"/"false"), rather than a check box.
              public Class<?> getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
              * Don't need to implement this method unless your table's editable.
              public boolean isCellEditable(int row, int col) {
                   // Note that the data/cell address is constant,
                   // no matter where the cell appears onscreen.
                   // return false;
                   return true;
              * Don't need to implement this method unless your table's data can
              * change.
              public void setValueAt(Object value, int row, int col) {
                   if (DEBUG) {
                        System.out.println("Setting value at " + row + "," + col
                                  + " to " + value + " (an instance of "
                                  + value.getClass() + ")");
                   data[row][col] = value;
                   fireTableCellUpdated(row, col);
                   if (DEBUG) {
                        System.out.println("New value of data:");
                        printDebugData();
              private void printDebugData() {
                   int numRows = getRowCount();
                   int numCols = getColumnCount();
                   for (int i = 0; i < numRows; i++) {
                        System.out.print(" row " + i + ":");
                        for (int j = 0; j < numCols; j++) {
                             System.out.print(" " + data[i][j]);
                        System.out.println();
                   System.out.println("--------------------------");
         * Create the GUI and show it. For thread safety, this method should be
         * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("TableRenderDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Create and set up the content pane.
              TableRenderDemo newContentPane = new TableRenderDemo();
              newContentPane.setOpaque(true); // content panes must be opaque
              frame.setContentPane(newContentPane);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              // Schedule a job for the event-dispatching thread:
              // creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();

  • How to make cell editable alv in WebDynpro for ABAP?

    I make Column editable ALV.(See under source code)
    But I can't make Cell editable ALV.
    How to make Cell editable ALV in WebDynpro for ABAP?
    and..how to get changed data?
    DATA: l_value TYPE REF TO cl_salv_wd_config_table.
      l_value = l_ref_interfacecontroller->get_model( ).
    * { EDITABLE
      DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
            lr_input_field     TYPE REF TO cl_salv_wd_uie_input_field,
            lr_column          TYPE REF TO cl_salv_wd_column.
      lr_column_settings ?= l_value.
      lr_column = lr_column_settings->get_column( 'TOTAL_COUNT' ).
      CREATE OBJECT lr_input_field
        EXPORTING
          value_fieldname = 'TOTAL_COUNT'.
      lr_column->set_cell_editor( lr_input_field ).
      DATA: lr_table_settings TYPE REF TO if_salv_wd_table_settings.
      lr_table_settings ?= l_value.
      lr_table_settings->set_read_only( abap_false ).

    the code seems to be correct....but where are you writing it?
    put the code in the wddoinit method and it should work.
    have a look at this article..
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3133474a-0801-0010-d692-81827814a5a1

  • Need help serializing an AbstractTableModel for a JTable with cell editing.

    Fun times are ahead. Here we go!
    I have a JTable that contains data I'd like to serialize out to a file to be restored and viewed later.
    So I tried saving the AbstractTableModel subclass out to a file. Whenever I do this, I get the following error message:
    java.io.NotSerializableException: javax.swing.JTable$CellEditorRemover
    Now I know for fact that serializing an AbstractTableModel that was installed in a JTable without cell editing works just fine (my old code did exactly that). As a result, I think that the code that handles events in the AbstractTableModel contains references back out to the JTable, which causes the JTable to be saved no matter what (even though I'm just interested in saving the TableModel only). It causes a bigger file than normal, but file size is not an issue. The only issue I have is that CellEditorRemover (an undocumented inner class of JTable), which is automatically installed for JTables with editable cells, is not serializable.
    This leads to the following questions:
    1. Is there a way to avoid serialization/deserialization of the CellEditorRemover inner class of JTable?
    2. Is there a way to save an AbstractTableModel without saving all of the event listeners associated with it?
    I think an answer to either of these questions would go a long way towards solving my problem. Otherwise, I'll resign myself to weeping silently in the corner of my office.
    Thanks!

    I would suggest that if you can you only save the
    data... but i would do this by using the
    externalizable interface.
    What you will need to do is have the
    writeExternal(ObjectOutputStream out) and
    readExternal(ObjectOutputStream out) methods in your
    class. These will be responsiable for saving the
    data.
    Here's an example of what you can do in these
    methods... this is just a little tidbit from a program
    i've written.public void writeExternal(ObjectOutput out) throws
    IOException {
              out.writeInt(size);
              out.writeObject(drawName);
              out.writeInt(playersLength);
    for(int i = 0; i < playersLength; i++)
    ) out.writeObject(players);
              out.writeInt(seedsLength);
    for(int i = 0; i < seedsLength; i++)
    ) out.writeObject(seeds[i]);
              out.writeInt(drawLength);
    for(int i = 0; i < drawLength; i++)
    ) out.writeObject(draw[i]);
    public void readExternal(ObjectInput in) throws
    IOException, ClassNotFoundException {
              size = in.readInt();
              drawName = (String)in.readObject();
              playersLength = in.readInt();
    for(int i = 0; i < playersLength; i++) players[i] =
    = (String)in.readObject();
              seedsLength = in.readInt();
    for(int i = 0; i < seedsLength; i++) seeds[i] =
    = (String)in.readObject();
              drawLength = in.readInt();
    for(int i = 0; i < drawLength; i++) draw[i] =
    = (String)in.readObject();
    You can now use your class as you would a Serializable
    class, but it will only save the data
    Hope this helped
    webaf409java
    I forgot to add some critical information in my original post. My apologies. :(
    I've thought about using Externalizable, but am hesitant to use it because the application would no longer be able to read in files using the old save format (ie, AbstractTableModels for JTables without CellEditorRemovers ).  I want to preserve the ability to read the old saved AbstractTableModel formats if possible. 
    Do you know of a way to revert to the default deserialization mechanism from readExternal?  This way, during deserialization, I could do a quick test on the object being read and have the ability to default to the regular deserialization mechanism if the object is of the old type or continue with the new Externalizable stuff if the object is one of the new type.  Maintaining file compatibility is key.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Toggle between allowing cell editing and disallowing....

    Hi,
    I have an edit button and when clicked it allows the user to edit all cells on the table, when clicked again all cell editing is disabled. I have a method which is called by the edit button event handler which works fine.. what to put in the method is the problem!
    I was using:
    private void setTableEnabled(boolean enable){
             if(enable)
                 table.setCellSelectionEnabled(true);
                 table.setEnabled(true);
                 table.setBackground(enabledTableColour);
             else
                 table.setCellSelectionEnabled(false);
                 table.setEnabled(false);
                 if(table.isEditing())
                 {     table.getCellEditor().stopCellEditing();
                 table.setBackground(disabledTableColour);
         }This code worked except when i use the table.setEnabled(false) my dropdowns don't work. The editing needs to be disabled when the application is loaded. i dont know why it effects my dropdown menus...
    Any ideas why or how i could go about it another way?
    Would really appreciate any help or insight!
    Thanks,
    Saz
    ***

    I was using:
    private void setTableEnabled(boolean enable){
             if(enable)
                 table.setCellSelectionEnabled(true);
                 table.setEnabled(true);
                 table.setBackground(enabledTableColour);
             else
                 table.setCellSelectionEnabled(false);
                 table.setEnabled(false);
                 if(table.isEditing())
                 {     table.getCellEditor().stopCellEditing();
                 table.setBackground(disabledTableColour);
    You should make use of the fact that a boolean can only have 1 of two values... You don't need to check it with an if, so your code can be rewritten as:
        private void setTableEnabled(boolean enable){
            table.setCellSelectionEnabled(enable);
            table.setEnabled(enable);
            if (enable) {
                table.setBackground(enabledTableColour);
            } else {
                table.getCellEditor().stopCellEditing();
                table.setBackground(disabledTableColour);
    This code worked except when i use the
    table.setEnabled(false) my dropdowns
    don't work. The editing needs to be disabled when the
    application is loaded. i dont know why it effects my
    dropdown menus...What dropdowns?

  • Making individual row or cell editable or readonly depend on cell data

    Dear expert
    I'm working with dataGrid and itemEditor. I can make some
    column editable. But I would like to know how to set some specific
    row or cell editable or readonly depend on cell data. Could anybody
    guide me which method should I override or any idea?
    Thanks

    Well a simply way would be if the row contained some kind of
    data that had the info to determine if it was editable or not...
    e.g. say the data in the dataProvider of the dataGrid has a field
    called jobTitle and you didn't want cells in that row editable when
    the jobTitle is "Executive".
    <mx:DataGrid dataProvider="{jobData}" editable="true">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn headerText="Title" dataField="Title"
    itemEditor="titleEditor"/>
    <mx:DataGridColumn headerText="Phone" dataField="Phone"
    itemEditor="phoneEditor"/>
    </mx:columns>
    </mx:DataGrid>
    Your itemEditor's could check to see if thats the case.
    phoneEditor.mxml
    <?xml version="1.0"?>
    <mx:TextInput xmlns:mx="
    http://www.adobe.com/2006/mxml"
    text="{data.Phone}" creationComplete="checkIfEditable()" >
    <mx:Script>
    public function checkIfEditable():void
    if(data.Title == 'Executive') this.editable=false;
    </mx:TextInput>

  • JTable and last cell edited

    Hi all,
    I have a jtable that is populated from an sql table.
    When I edit the cells, I push on a botton that updates the table.
    The problem I am facing is in the last cell edited, I need to click on another cell for me to be able to read its new value. i.e. in another word the cell needs to loose focus for me to be able to read is new values.
    Thanks in advance for your help.
    Best regards.
    Saadi MONLA

    Seems like a bug in JTable. Best solution is probably when the routine that feeds the new values into the JTable is completed, force a focus on a different cell and then back to your cell using an API method. If an API method doesn't exist to force focus to another cell (I just looked and didn't see one) then maybe executing a repaint() or something like that will cause it to redraw correctly.

  • Disable cell editing

    Hi.
    Can I disable cell editing in a JTable without using a TableModel and still let the user click on different cells?
    /lars

    You can subclass JTable and override isCellEditable().

  • Focus Lost on Tree Cell Edit

    I am trying to force changes made in a tree cell edit when focus to that tree node has been lost(like on an enter button press) but it always reverts to the old value. i have tried adding a CellEditorListener to force an enter key press on the editingCanceled action but this still reverts the value.
    Anyone have any ideas on how to fix this?
    Thanks.

    Hi,
    Try to use
        call method cl_gui_control=>set_focus exporting control = grid1.

  • JTable - disable cell editing for whole table

    I need to know how to disable cell editing for the whole of a JTable. Is there an easy way of doing this??

    you can do it very easy :)
    just override AbstractTableModel's isCellEditable(int row, int col) function
    and return false is ok.
    Hope this helps!

  • Reporting query - Cell editing

    Hi Experts !!
    I need some documents related to embedding multiple queries and formatting a workbook.
    I need more info on cell editing.
    Appreciate your help !!
    Thanks.

    hi yogita,
    Check the below link for checking the cell editing functionality
    [Cell editing|http://sap.seo-gym.com/celleditingBex.pdf]
    Regards
    KP
    have you tried to search in google of SDN before posting?

  • IsCellEditable() to disable cell editing for specific columns

    Hello experts:
    My SSCCE for this question is at the below link:
    http://forum.java.sun.com/thread.jspa?threadID=5293914&messageID=10244030#10244030
    My question is how do I disable cell editing for all but the "Price" column of my table in the SSCCE. I tried adding the below lines of code right after creating the JTable. But get compilation errors.
    //Here is the block of code that I am trying to include.
         @Override                                                       
         public boolean isCellEditable(int row, int col) {     
         if (col == 7) {                                                  
                   return true;
              } else {
                   return false;
         } //Below is the method in detail03.java showing the block of code added
    private JScrollPane BuildEmptyTable() {
         model = new DefaultTableModel();
         model.addTableModelListener( this );
         model.setColumnIdentifiers(new String[] { "SKU","Qty", "Price"});
            tblDetailTest = new JTable(model);
         @Override                                                       
         public boolean isCellEditable(int row, int col) {     //     <----- I tried placing the
         if (col == 7) {                                        //                  the code block here
                   return true;
              } else {
                   return false;
         tblDetailTest.setRowHeight(20);
         tblDetailTest.setPreferredScrollableViewportSize(new Dimension(900, 100));
         JTableHeader tblHdr = tblDetailTest.getTableHeader();
         tblHdr.setBackground(Color.yellow);
         JScrollPane scrollPane = new JScrollPane(tblDetailTest);
         return scrollPane;
    }Can somebody please guide me? Thank you very much.

    oops!
    Sorry, my bad! I did not tell you what I tried. Following your suggestion, I made the following 2 changes to the code:
    In the method, BuildEmptyTable(), where I build the table structure, I have the following statement:
         tblDetail = new JTable(model){
    public boolean isCellEditable(int row, int col) {
           return col == 8;
    };And in a separate method after the table is populated with data, I have the below code:
         tblDetail.getModel().addTableModelListener(new TableModelListener() {
         public void tableChanged(TableModelEvent e) {
         if (e.getType() == TableModelEvent.UPDATE)
              int row = e.getFirstRow();
              int column = e.getColumn();
                 if (column == 8){
                   //code here
                   System.out.println("Updating item price!");
         }I do understand that the message gets displayed as many number of times equal to number of rows inserted into the table, because of the UPDATE event. But my problem is I do not know how to make a code change to do what I exactly want, as I have indicated in my previous note. Meaning I want the listener to be called only when the
    data in the editable cell changes.
    Thank You.

Maybe you are looking for

  • Data is not getting posted to R/3 from CRM

    Hi to All, When i am creating sales order in CRM data is not getting replicated to R/3. System is showing that B Doc is created , posted and validated. But here in CRM system outbound queue is generated but in R/3 there is no data in inbound queue. C

  • Ram problem! (msi z68-gd80,g3)

    Hey there. have a problem with my new ripjaw x series ram 1866. ( and all other ram) Tried installing all 16 gb of it earlier today and apparently only the first blue and black ram slot work. Before i updated my bios to the newest one the pc wouldn't

  • Inspection lot problem during inbound delivery

    Hi, I am facing following issue during inbound delivery. I have activated inspection type 01 in material master for a packing material. Created a PO for the material through ME21N. PO created. Now I am creating inbound delivery through VL31N with ref

  • HR_INFOTYPE_OPERATION not Working for IT0002 while Hire

    Hi all , we have created a report which picks the file from the Application Server for creating Employee in HR. First created Position and Used FM 'HR_PAD_HIRE_EMPLOYEE'  to create Employee Pernr. After which I have used 'HR_INFOTYPE_OPERATION'  for 

  • Link objects in reports visible without permission

    I am creating reports that have links to forms. I wish these links to be disabled when someone is not provided permissions to the link or to the resulting form. I have created link objects and set the permissions for public to not have access, but th