Saving table cell editor value when switch to other cell

Hello,
I have the code below to allow user entering integer values in a table cell. What I want is that if the user switch to an other cell than I want to save the editor value. It works fine if the user press the Enter button, but how can I do this when user clicks or press tab, arrow to switch to an other cell?
public class IntegerEditor extends AbstractCellEditor implements TableCellEditor, ActionListener{
     JFormattedTextField component = new JFormattedTextField(NumberFormat.getIntegerInstance());
     public IntegerEditor(){
          component.addActionListener(this);
                                          component.setBorder(null);             
     public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                      if (value != null)  component.setValue(value);
                      return component;
     public Object getCellEditorValue() {
          return Integer.valueOf(component.getValue().toString());
     public void actionPerformed(ActionEvent e) {
          fireEditingStopped();
}

Hello camickr,
I add a column to the table with the function see below.
With this sollution I the cell value saving is working fine, but it accept string vales for me :(
If I use the JFormattedTextField than it accepts only integers but I have the original problem. I'm using fireEditingStopped(); in the focusLost method but it has no effect.
What do I wrong?
public TableColumn addNewIntegerColumn(java.lang.String caption, int width, boolean fix) {
      //Switch off AutoCreate
      this.setAutoCreateColumnsFromModel(false);
      //Create a new Column
      TableColumn col = new TableColumn(dataSheet.getColumnCount(),width,new LabelRenderer(),this.getDefaultEditor(Integer.class) );
      //Set column header
      col.setHeaderRenderer(new HeaderRenderer());
      col.setHeaderValue(caption);
     if (fix) col.setResizable(false);
      col.setPreferredWidth(width);
      //Add column to the table
      this.addColumn(col);
      //Add column to the model
      dataSheet.addColumn(caption);
      return col;
}

Similar Messages

  • Screen of my desktop hangs when switching to other desktop or mission control

    Screen of my desktop hangs when switching to other desktop or mission control. There is tearing of graphics while switchin to different desktops or mission control or while scrolling a webpage. I wish to know the problem and its solution.

    I have a Mac Pro 13' and I am using OS X Mavericks.

  • Volume good on my admin account. When switch to other accounts no volume. What to do?

    Volume & sound are good on my Admin account on my iMac. When switching to others account on my iMac no sound at all!

    Un-install using the developer’s instructions to make sure you remove all parts of the application. Some people recommend not installing an application unless you know how to remove it.
    Cuda has caused some people problems. Try un-installing it and test.
    Try setting up another admin user account to see if the same problem continues. If Back-to-My Mac is selected in System Preferences, the Guest account will not work. The intent is to see if it is specific to one account or a system wide problem. This account can be deleted later.
    Isolating an issue by using another user account
    If the problem is still there, try booting into the Safe Mode using your normal account.  Disconnect all peripherals except those needed for the test. Shut down the computer and then power it back up after waiting 10 seconds. Immediately after hearing the startup chime, hold down the shift key and continue to hold it until the gray Apple icon and a progress bar appear. The boot up is significantly slower than normal. This will reset some caches, forces a directory check, and disables all startup and login items, among other things. When you reboot normally, the initial reboot may be slower than normal. If the system operates normally, there may be 3rd party applications which are causing a problem. Try deleting/disabling the third party applications after a restart by using the application un-installer. For each disable/delete, you will need to restart if you don't do them all at once.
    Safe Mode
    Safe Mode - About

  • When I call other cell phones, the recipient hears an echo of his/her own voice.  What causes this?

    When I call other cell phones or receive calls from other cell phones, the other party hears an echo of his/her own voice.  I do not hear the echo. Is there something wrong with my iPhone 4S?

    happens once in awhile. jsut the established connection.

  • Is there a way to make a number of cells add to a certain number. I need 5 or 6 cells to add to 1700. If one of the cells becomes 0, I need the other cells to change so the bottom number stays at 1700.

    is there a way to make a number of cells add to a certain number. I need 5 or 6 cells to add to 1700. If one of the cells becomes 0, I need the other cells to change so the bottom number stays at 1700.

    Okay then. If your seven numbers are in column B then the formula next to each number in column C would be
    =IF(B=0,0,1700/COUNTIF(B,">0"))
    This assumes all non-zero numbers are positive numbers. The sum will be 1700.

  • Cell editor removed when table resized

    I'm using Java 1.5.0_06 in my application. I have a JFrame which contains a JTable. I use FormLayout (which is like GridBagLayout). When the frame resizes, the table resizes too.
    When I enter edit mode in a cell of the table and resize the frame (and the table), the cell exits edit mode. The editor of the cell is removed when the table is resized which causes the value that I had entered in the cell to be lost.
    Is there a way to stop cell editing when the frame is resized instead of the cell just exiting edit mode.
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableModel;
    import com.jgoodies.forms.factories.FormFactory;
    import com.jgoodies.forms.layout.CellConstraints;
    import com.jgoodies.forms.layout.ColumnSpec;
    import com.jgoodies.forms.layout.FormLayout;
    import com.jgoodies.forms.layout.RowSpec;
    public class ResizableTableTest extends JFrame {
         final JScrollPane _scrollPane;
         public static void main(String[] args) {
              ResizableTableTest frame = new ResizableTableTest();          
                frame.addWindowListener(new WindowAdapter() {
                     public void windowClosing(WindowEvent e) {
                          System.exit(0);
                frame.setSize(451, 340);
                frame.setVisible(true);
         public ResizableTableTest() {
              super();
              getContentPane().setLayout(new FormLayout(
                   new ColumnSpec[] {
                        new ColumnSpec("default:grow(1.0)"),
                        FormFactory.RELATED_GAP_COLSPEC,
                        FormFactory.DEFAULT_COLSPEC},
                   new RowSpec[] {
                        new RowSpec("default:grow(1.0)"),
                        FormFactory.RELATED_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.RELATED_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.RELATED_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.RELATED_GAP_ROWSPEC,
                        FormFactory.DEFAULT_ROWSPEC}));
              _scrollPane = new JScrollPane();
              getContentPane().add(_scrollPane, new CellConstraints(1, 1, CellConstraints.FILL, CellConstraints.FILL));
              addTableToScrollPane();
         private void addTableToScrollPane() {
               JTable table = new JTable();
             DefaultTableModel model = (DefaultTableModel)table.getModel();
             table.setRowSelectionAllowed(false);
             table.setCellSelectionEnabled(true);
             //Add some columns
             model.addColumn("column A");
             model.addColumn("column B");
             model.addRow(new Object[]{"item1", "apple"});
             model.addRow(new Object[]{"item2", "banana"});
             model.addRow(new Object[]{"item3", "carrot"});
             model.addRow(new Object[]{"item1", "grape"});        
             _scrollPane.setViewportView(table);          
    }thanks,

    I would assume that on the resize of the table the
    editing cancelled event is being fired...
    You could try overriding the method in the JTable and
    when it gets fired, fire the editing stopped method
    instead... not sure whether that will work thoughI tried that, but it didn't help. On searching for this problem, I saw a bug report on this very problem.
    Here's info on a related bug in java:
    Cell editing does not complete when JTable loses focus
    Lost newly entered data in the cell when resizing column width
    And here's an interesting article:
    Why Editable Table Cells Are Evil
    Message was edited by:
    petes1234

  • JTable Cell grays out when I click the cell below (JList editor & renderer)

    Click on any cell, then click on the cell immediately below.. and the first cell u clicked on goes gray... After repaints and stuff, it stills stays gray
    * TimetableCellGui.java
    * Created on April 12, 2007, 7:21 PM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package timetable.gui;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Font;
    import java.util.ArrayList;
    import java.util.EventObject;
    import javax.swing.DefaultListModel;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.event.CellEditorListener;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableCellRenderer;
    * @author jay
    public class TimetableCellGui extends JList implements TableCellRenderer, TableCellEditor {
         * Creates a new instance of TimetableCellGui
        public TimetableCellGui() {
            this.setFont(new Font("Nice",Font.PLAIN,10));
            this.setForeground(new Color(150,150,250));
        private static String courseFilter = "";
        private static String roomFilter = "";
        private static boolean filterCourse = false;
        private static boolean filterRoom = false;
        public static String getCourseFilter() {
            return courseFilter;
        public static String getRoomFilter() {
            return roomFilter;
        public static boolean isFilterCourse() {
            return filterCourse;
        public static boolean isFilterRoom() {
            return filterRoom;
        public static void setCourseFilter(String c) {
            courseFilter = c;
        public static void setFilterCourse(boolean f) {
            filterCourse = f;
        public static void setFilterRoom(boolean filter) {
            filterRoom = filter;
        public static void setRoomFilter(String r) {
            roomFilter = r;
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if(value == null) {
                return null;
            } else {
                DefaultListModel model = new DefaultListModel();
                String addition = "some addition";
             model.add(addition);          
                model.add(addition);                
                this.setModel(model);
                return new JScrollPane(this);
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            if(value == null) {
                return null;
            } else {
                DefaultListModel model = new DefaultListModel();
                String addition = "some addition";
             model.add(addition);                          
                this.setModel(model);
                return new JScrollPane(this);
        public Object getCellEditorValue() {
            return "helllo";
        public boolean isCellEditable(EventObject anEvent) {
            return true;
        public boolean shouldSelectCell(EventObject anEvent) {
            return true;
        public boolean stopCellEditing() {
            return true;
        public void cancelCellEditing() {
            super.clearSelection();
        public void addCellEditorListener(CellEditorListener l) {
        public void removeCellEditorListener(CellEditorListener l) {
    }

    I'm doing up a timetable. And so far, I've found that is the best way to display it. However if you can think of a better way, I'm willing to listen, but if u havn't gotten a better suggestion... Plz try and help me tweak this one to work... Because I've done quite a bit of work on this one so far

  • Cell Editor to limit characters in jtable cell

    Hello Java Gods,
    Can anyone help me or write for me a custom cell editor/renderer to limit the max number of characters in a jtable cell to be 10? By this, I mean, the user should not be able to type more than 10 characters in this particular cell.
    Any help would be greatly appreciated. I have to hand in this code before this evening. So please please help me folks.
    Thanking you all in advance.
    Warm Regards,
    Java Newbie

    Try one of these CellEditors:
    class LimitedEditor extends DefaultCellEditor {
        public LimitedEditor() {
            super(new JTextField());
        public boolean stopCellEditing() {
            String value = ((JTextField) getComponent()).getText();
            if (!value.equals("")) {
                if (value.length() > 10) {
                    ((JComponent) getComponent()).setBorder(new LineBorder(Color.red));
                    JOptionPane.showMessageDialog(null, "String length cannot be bigger than 10");
                    return false;
            return super.stopCellEditing();
        public Component getTableCellEditorComponent(final JTable table, final Object value,
                final boolean isSelected, final int row, final int column) {
            JTextField tf = ((JTextField) getComponent());
            tf.setBorder(new LineBorder(Color.black));
            if (value == null) {
                tf.setText("");
            } else {
                tf.setText(value.toString());
            return tf;
    class LimitedEditor2 extends DefaultCellEditor {
        public LimitedEditor2() {
            super(new JTextField());
            JTextField tf = ((JTextField) getComponent());
            tf.setDocument(new PlainDocument() {
                public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
                    int len = getLength();
                    if (len + str.length() > 10) {
                        Toolkit.getDefaultToolkit().beep();
                    } else {
                        super.insertString(offs, str, a);
    }Usage example:
            TableColumn tc = table.getColumnModel().getColumn(1);
            tc.setCellEditor(new LimitedEditor2());]

  • FCP 7 crashes only when switching to other applications/finder

    Hi everyone,
    I've been working on a feature film for about 9 months in FCP 7.  All went fine.  I regularly backed up, copied to new projects (have had a few bad experiences with corrupted projects) and have otherwise had no problems.
    Last night, all of a sudden, I got the spinning wheel of death while tidying something up.  FCP crashed.  No problem, I restarted it but the same thing happened again.  I trashed my prefs, figure that would fix it but it didn't.  Very strange because I didn't change anything with the project and the file itself is not that big, maybe 35 mb.
    After about 20 crahses I figured out that it only crashes when I switch between FCP and another application, say Safari.  I can work away on the project, but as soon as I cmd+tab to any other app (including finder) when I go back to FCP I get the spinning wheel and it eventually shows up as not responding.
    I have re-installed FCP 3 times since yesterday, re-installed the OS, repaired the disk permissions, trashed the pref's A LOT, and have now even upgraded the OS to Lion - none of this has had any effect.
    If someone sees something obvious that I'm missing please let me know.  I'm tearing my hair out here.  Searching extensively only doesn't seem to yield much.
    I'm using a MacPro 1.1, OSX 10.7.4, 2x 3 ghz quad core processors and 14 gb ram.
    Thank you for your time
    Rick

    I've had this problem too and figured out a solution to try before evicerating your system and trial and erroring RAM back into socket.
    If you edit anything like I do you like to always be able to go back after making changes so you save all of your old sequences just in case you need to reference them later.  While working on a televison show my FCP projects for each episode consisted of a sequence for each show act and a master sequence of the entire show run, all of which I copied and saved at the end of each day so I could backtrack changes if I needed to.  Multiply this process by two weeks or so and pretty soon my episode projects consisted of at least 28-32 separate sequences in addition to all my media links, music, SFX, etc.
    The solution that worked for me was to copy my current project and delete all the old sequences saving only the most recent two copies of my work;keeping a backup copy of my old work but removing them from my active project.
    I had to do this folder by folder, about 4 sequences at a time) to prevent FCP from crashing in the middle of the delete but once it was done the problem was solved.  I can switch back and forth between applications without any consequence and I'm back on track and able to work again.  I've since adjusted my workflow so that when I hit four days worth of sequences I duplicate the project and (in the copy) I delete all the past sequences and start from my current cut.  e.g. If I worked for one week and have five folders of past sequences then at the beginning of the next week I copy the whole project, delete the old material and start from my current cut.  If I need to reference old changes I just open up the old project and it's all available without crippling my system.
    As best as I can determine the crashes are a result of Final Cut trying to refresh media links to too many things when you toggle back to it from another progam and locking up.  This seemed to solve the problem.
    Hope it helps.
    ~"70% of user error results in software issues 100% of the time"

  • Table font size changes when I set other font property

    I had anomalous behavior in a VI i wrote so I did the following to troubleshoot it.  Can anybody explain what's going on?
    I created a table indicator and changed the font size to 36 for a 5x5 area cells using mouse-drag-select and the front panel "Xpt Application Font" dropdown.  I changed one of the rows to font=strikeout using the same front panel dropdown.    I then used the FOR loops and properties as below to change the stikeout property to FALSE for all 5 rows.  Running the VI caused the font size of all of the text to change, even though the CellFontSize property was not set anywhere in the VI.  I manually set the font sizes to 36 again and subsequent runs of the the VI did not affect the font sizes. 

    I did not attach the code because after it runs it is "fixed".  The FOR loop I described is easy enough to recreate but it seems there was an issue with the image in the first post so I've attached it here (rather than try again to include it in the message). 
    Attachments:
    table_font.png ‏12 KB

  • Issue: The user name changed when switch to other links in SCN

    Hi,
    I just wanted to bring to the notice of the moderators (as I don't know where can I report for the IT related issues) that for the past few days I am facing a peculiar behaviour when I log into the SCN through Internet Explorer 8.0. This is also being faced by my peers too..:)
    The issue is that when I login to SCN, I can see my user name on the top of the page(Home page). But when I switch to say 'Forum', the user name is changed and this is random. I kind of have access to his/her account.
    Even I try to log off, nothing happens.. The only solution left is to close the IE and then try to login again.
    Kindly have a look into this issue.
    Thanks in advance..:)
    Regards
    Amit

    Ive (along with many others) noticed the same problem with the Forums about 2 years ago, where after log-in or clicking a certain thread I find myself in someone's else's id. And the id keeps changing from time to time with no end in sight.
    The problem took about a couple of days to be rectified.
    pk

  • How to extend the selection from cell to row when click one sepecial cell

    The JTable contains a special column to display the line number for each row. When user click on the first column(contains row number), the selection would extend to the whole row(React something like Excel). How can i achieve that?
    And how to achieve that for TableHeader?
    Thanks a lot!
    1|
    #|###########################
    3|
    4|

    Check out this posting for one way to do this:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=594338

  • Excel 2007 cell color changes when copying to other docum. using clipboard

    Hi,
    There is excel 2007 document which is generated by SAP. I think it contains
    some VB macros and some grouping.
    The problem is that if I select something from that document, copy that and
    paste to another excel 2007 document - colors get inverted somehow - for
    example white cell becomes red cell (backgroud color I mean), other
    background colors changes as well.
    If I open this xlsx document using excel 2003 (it converts document using
    compatibility pack) the issue is gone - I can copy contents to other excel
    2003 document without losing any format info.
    The problem is that our users all use office 2007.
    What could couse this behaviour ?
    thanks in advance
    Vilius
    Edited by: Vilius Mockunas on May 25, 2009 8:04 AM

    dear friend,
    you would do:
    1. search SAP Notes;
    2. check out the updates/patches for your MS Office;
    3. replicate it on another computer/another sap user (make sure it is a local issue)
    good luck!

  • Way to make Reader Mobile (IOS/Android) to fill in form cells based on input made in other cell?

    Hi, Is there a way to make Acrobat Reader Mobile (IOS/Android) to fill in form cells based on input in another cell?
    I made a timesheet where based on an activity code input in a dropdown box the description corresponding the activity code is displayed automatically in another cell.(see below)
    This is working flawlessly as long as I am using a PC, however does not work on any kind of phone.(I suppose this feature is not supported on Acrobat Mobile yet)
    My question is if anybody can suggest an alternative method for mentioned feature which works also on phones?
    Any suggestion would be much appreciated
    In the Format field:
    if(event.willCommit)
    console.println(event.value);
    switch(event.value)
       case "    1      01":
        this.getField("REMARK1").value = "Offloading";
        break;
       case "    2      01":
        this.getField("REMARK1").value = "Preparation";
        break;
       case "   19     44":
        this.getField("REMARK1").value = "Support-3rd party insp/contract.";
        break;   case " ":
        this.getField("REMARK1").value = " ";
        break;
    Regards: Robert

    Try getting rid of that console.println statement. If that doesn't help, it should work if you convert that from a format script of the dropdown to a calculate script of the REMARK1 field.

  • FocusLost of jtable is not triggered when focus is lost from a cell editor.

    Hi
    I have a jtable and some columns in the table contains editable cells. I started editing a cell and, before the cell editing is stopped, i clicked another component in the panel using mouse. At that time, the focusLost() method of the table is not triggered. So that the code written in my focusLost() method of table is not working.
    If I add focuslistener to the cell editors, the focusLost() method of this cell editors are triggered at that time.
    Shall I need to add focuslistener to each cell editors used in my jtable ? Anybody know a better solution to handle this problem ?
    Regards
    Anoop

    Add this to your code.
    yourTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

Maybe you are looking for