Celleditor in jtable depending on value in other cell

here is the situation:
I have a jtable with 2 columns (colA en colB). colA can have 5 different values. For every value that colA can contain colB should be edited in a different way. For example:
colA value: val1 --> colB editor: defaultcelleditor (jtextfield1);
colA value: val2 --> colB editor: customcelleditor (jtextfield1);
colA value: val3 --> colB editor: customcelleditor (jcombobox1);
I already tried it this way:
class customJTable  extends JTable
// .... some code, constructors, ....
public  TableCellEditor getCellEditor()
        if (getValueAt(row,col).equals("val1"))
             return new DefaultCellEditor(jtextfield1);
        else if (getValueAt(row,col).equals("val2"))
          return new customCellEditor(jtextfield1);
          else
             return newDefaultCellEditor("jtextfield1");
public class customCellEditor extends DefaultCellEditor
  // cell editor code
}if i use this code the jtable doesn't adapt the celleditor and uses the celleditor default in jtable. A second problem is that the celleditor isn't removed when editing is stopped
any help would be greatly appreciated
brecht
ps: i use jdk 1.4.2

super, it works like a charm with the defaultcelleditor. thx a lot.
But i have a problem with my onw celleditor. When the editing of the cell is stopped the editor isn't removed. I think i've already read something on the forum about a bug in celleditorremover... I will look it up. ..
public class OverwriteDefaultCellEditor extends DefaultCellEditor
       public OverwriteDefaultCellEditor(JTextField textField) {
             super(textField);
      public Component getTableCellEditorComponent(
      JTable table,
      Object value,
      boolean isSelected,
      int row,
      int column)
      ((JTextField)getComponent()).setText(value.toString());
      ((JTextField)getComponent()).selectAll();
      return getComponent();
[\code]

Similar Messages

  • Insert a button that will paste a value from one cell to another

    I'm hoping to be able to insert a button on a form that, when clicked, will copy the values of certain cells and paste those values into other cells on the same form.
    I'm looking to insert another botton that, when clicked, will take the value in one particular cell and add 1 to the value.
    Is it possible to have one button perform both actions?

    I had add the code in my AMimpl method
    below is my code
       ViewObjectImpl vo = this.getGlJrnlHd1();
            Row newRow = vo.createRow();
            ViewObjectImpl c1 = this.getCursorC1_1();
            Row cr1 = vo.getCurrentRow();
            System.out.println ("Curretn row:"+vo.getCurrentRow());
               System.out.println (cr1.getAttribute("GrhBu"));
            newRow.setAttribute("GjhBu", cr1.getAttribute("GrhBu"));
           newRow.setAttribute("GjhPlant", cr1.getAttribute("GrhPlant"));
          newRow.setAttribute("GjhJrnlType", cr1.getAttribute("GrvlJrnlType"));
           newRow.setAttribute("GjhJrnlNo", cr1.getAttribute("GrvlJrnlNo"));
           newRow.setAttribute("GjhJrnlSfx", cr1.getAttribute("GrhJrnlSfx"));
           newRow.setAttribute("GjhJrnlDate", "Null");
           newRow.setAttribute("GjhYear", cr1.getAttribute("GrvlYear"));
           newRow.setAttribute("GjhPeriod", cr1.getAttribute("GrvlPeriod"));
           newRow.setAttribute("GjhDesc", cr1.getAttribute("GrhDesc"));
           newRow.setAttribute("GjhAppl", "GLM");
           newRow.setAttribute("GjhReversal", "N");
           newRow.setAttribute("GjhStatus","N");
           newRow.setAttribute("GjhCreBy", "NULL");
           newRow.setAttribute("GjhCreDate", "NULL");
           newRow.setAttribute("GjhUpdBy", "NULL");
           newRow.setAttribute("GjhUpdDate", "NULL");
           this.getTransaction().commit();

  • Shading part of a JTable Cell dependent upon the value of the cell

    Hi
    Was hoping some one woudl be able to provide some help with this. I'm trying to create a renderer that will "shade" part of a JTable cell's background depending upon the value in the cell as a percentage (E.g. if the cell contains 0.25 then a quarter of the cell background will be shaded)
    What I've got so far is a renderer which will draw a rectangle whose width is the relevant percentage of the cell's width. (i.e. the width of the column) based on something similar I found in the forum but the part I'm struggling with is getting it to draw this rectangle in any cell other than the first cell. I've tried using .getCellRect(...) to get the x and y position of the cell to draw the rectangle but I still can't make it work.
    The code for my renderer as it stands is:
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import javax.swing.JLabel;
    import javax.swing.JTable;
    import javax.swing.table.TableCellRenderer;
    public class PercentageRepresentationRenderer extends JLabel implements TableCellRenderer{
         double percentageValue;
         double rectWidth;
         double rectHeight;
         JTable table;
         int row;
         int column;
         int x;
         int y;
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
              if (value instanceof Number)
                   this.table = table;
                   this.row = row;
                   this.column = column;
                   Number numValue = (Number)value;
                   percentageValue = numValue.doubleValue();
                   rectHeight = table.getRowHeight(row);
                   rectWidth = percentageValue * table.getColumnModel().getColumn(column).getWidth();
              return this;
         public void paintComponent(Graphics g) {
            x = table.getCellRect(row, column, false).x;
            y = table.getCellRect(row, column, false).y;
              setOpaque(false);
            Graphics2D g2d = (Graphics2D)g;
            g2d.fillRect(x,y, new Double(rectWidth).intValue(), new Double(rectHeight).intValue());
            super.paintComponent(g);
    }and the following code produces a runnable example:
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableModel;
    public class PercentageTestTable extends JFrame {
         public PercentageTestTable()
              Object[] columnNames = new Object[]{"A","B"};
              Object[][] tableData = new Object[][]{{0.25,0.5},{0.75,1.0}};
              DefaultTableModel testModel = new DefaultTableModel(tableData,columnNames);
              JTable test = new JTable(testModel);
              test.setDefaultRenderer(Object.class, new PercentageRepresentationRenderer());
              JScrollPane scroll = new JScrollPane();
              scroll.getViewport().add(test);
              add(scroll);
         public static void main(String[] args)
              PercentageTestTable testTable = new PercentageTestTable();
              testTable.pack();
              testTable.setVisible(true);
              testTable.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }If anyone could help or point me in the right direction, I'd appreciate it.
    Ruanae

    This is an example I published some while ago -
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Fred120 extends JPanel
        static final Object[][] tableData =
            {1, new Double(10.0)},
            {2, new Double(20.0)},
            {3, new Double(50.0)},
            {4, new Double(10.0)},
            {5, new Double(95.0)},
            {6, new Double(60.0)},
        static final Object[] headers =
            "One",
            "Two",
        public Fred120() throws Exception
            super(new BorderLayout());
            final DefaultTableModel model = new DefaultTableModel(tableData, headers);
            final JTable table = new JTable(model);
            table.getColumnModel().getColumn(1).setCellRenderer( new LocalCellRenderer(120.0));
            add(table);
            add(table.getTableHeader(), BorderLayout.NORTH);
        public class LocalCellRenderer extends DefaultTableCellRenderer
            private double v = 0.0;
            private double maxV;
            private final JPanel renderer = new JPanel(new GridLayout(1,0))
                public void paintComponent(Graphics g)
                    super.paintComponent(g);
                    g.setColor(Color.CYAN);
                    int w = (int)(getWidth() * v / maxV + 0.5);
                    int h = getHeight();
                    g.fillRect(0, 0, w, h);
                    g.drawRect(0, 0, w, h);
            private LocalCellRenderer(double maxV)
                this.maxV = maxV;
                renderer.add(this);
                renderer.setOpaque(true);
                renderer.setBackground(Color.YELLOW);
                renderer.setBorder(null);
                setOpaque(false);
                setHorizontalAlignment(JLabel.CENTER);
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
                final JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
                if (value instanceof Double)
                    v = ((Double)value).doubleValue();
                return renderer;
        public static void main(String[] args) throws Exception
            final JFrame frame = new JFrame("Fred120");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(new Fred120());
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    }

  • Changing a row colour in JTable, depending on a column value

    Hi,
    I need assistance with the following:
    I need to change the colour of a row in a JTable, depending on a column value. I have been successful on changing one column's colour in each cell, depending on the value by using a CellRenderer extending DefaultTableCellRenderer.I am unable to set the other 2 columns's cell's depending on the first column value's.
    I would appreciate any help, source would be a bonus.
    Thx
    Charl

    Ok, here follows the code as requested. Note that this is the code setting each row in one of my columns depending on the value. Now i have to cgange column0 and column1 's foreground the same as what this column (column2) 's foreground is. Thx
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    class ColorizedCell extends DefaultTableCellRenderer {
    static Hashtable cache;
    static {
    cache = new Hashtable();
    cache.put ("Device Responding to Poll",Color.green);
    cache.put ("Wan link Recovered",Color.green);
    cache.put ("No Response to Device Poll",Color.yellow);
    cache.put ("Wan Link Failure",Color.red);
    cache.put ("Lan Link Failure down",Color.red);
    cache.put ("Device Down",Color.red);
    public Component getTableCellRendererComponent(JTable table,
    Object value, boolean isSelected,
    boolean hasFocus, int row, int column)
    JLabel label = (JLabel) super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
    label.setText((String)value);
    if(column == 2) {
    //setFont(bold);
    Color c = (Color)cache.get(value);
    label.setForeground(c);
    if (isSelected) {
    label.setOpaque(true);
    label.setBackground(Color.white);
    else {
    //setFont(plain);
    label.setForeground(Color.white);
    return label;
    }

  • JTable:  Howto: Row color depending on value

    Hi all
    I would like to write a cell renderer that changes the background color of a row (or indivicual cells) depending on the value in one of the table columns. For example, if the value in column 'recursive' of a given row is 'true' then make the row (cell) backgroundd grey. if 'false' make white.
    I ve been able to write a simple cell renderer:
    public class colorTableCellRenderer extends DefaultTableCellRenderer
    java.awt.Color recursiveBG = new java.awt.Color(240, 240,240);
    public colorTableCellRenderer()
    super();
    public void setValue(Object value)
    String text = (String)value;
    this.setBackground(recursiveBG);
    this.setText(text);
    But i am lost on how to actually check the value of the other column so I can determine which color to choose.
    Help is greately appreciated.
    Cheers,
    michael

    Hi Laszlo
    Ok, I think this needs an explanation. Here is what I want to do:
    1. Depending on the value of column 0 compared to an external value (referenced), I want to mark a row by setting the background of the row to recursiveBG. All others should have a white background.
            if(selectedPerson.equals(sourceID)) // row is not recursive
              this.setBackground(Color.white);
            else // row IS recursive
              this.setBackground(recursiveBG);
              }This should just set the background color of the cell. If I select the row, the 'normal' behaviour should mark the row blue (or whatever is standard). Your counting is right, these states should be accomodated for.
    Current full code is below:
    public class colorTableCellRenderer extends DefaultTableCellRenderer
      java.awt.Color recursiveBG = new java.awt.Color(240, 240,240);
      int recursiveColumn = 4;
      String recursiveID = null;
      Connect connectRef = null;
      public colorTableCellRenderer(Connect connectRef)
        super();
        this.connectRef = connectRef;
      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
            java.awt.Color recursiveColor = new java.awt.Color(240,240,240);
            String myVal = (String)value;
            this.setText(myVal);
            recursiveID = (String)table.getValueAt(row, recursiveColumn);
            String selectedPerson = connectRef.getSelectedPersonPID();
            String sourceID = (String)table.getValueAt(row, 6);
            if(selectedPerson.equals(sourceID)) // row is not recursive
              this.setBackground(Color.white);
            else // row IS recursive
              this.setBackground(recursiveBG);
              return this;
    [/CODE]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Calculate a measure depending on the value of other dimension

    HI,
    I would like to know if it’s possible to calculate a measure depending on the value of other dimension. I want to calculate this measure in the Business Model and Mapping. I show you how I am trying to do it:
    http://img338.imageshack.us/img338/2496/imagenjp.png
    But when I try to make an aggregation of this measure then I get an error of consistency.
    I think a good example to make you to understand me is the function TODATE which calculates an aggregation depending on one time dimension. I would like to do the same thing but regarding to the value of other dimension.
    Can someone help me? Thanks a lot.

    Hi,
    Do you have that dimension table as a "Sources" in that BMM folder? if yes, then you can use the "Data Type" option and click on "show all logical sources". Then click on your fact table using which you want to do the calculation and then use this formula. After that you can have the aggregation.
    It should work.
    Thanks,
    Rohit

  • Set the color of a row depending the value of the column in JTable?

    Hi All,
    I have a JTable that add rows when the user clicks on the button. In this way there can be any no. of rows in my table. My table contains five columns. When a new row is added , it is added with new data each time. Also the data of the rows keep on changing time to time.
    My problem is that when the data value for the third column comes out to be -ve then color of the row should be red and if its value is +ve then the color of the row should be green.
    I have tried for this in the way but it is not working properly.
    public Component prepareRenderer(TableCellRenderer renderer,int rowIndex, int vColIndex)
         Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
    if(change<0 && rowIndex<table.getRowCount() )
              c.setForeground(Color.red);
              c.setFont(new Font("TimesRoman",Font.PLAIN,11));
    else if(change>0&&rowIndex<table.getRowCount() )
    c.setForeground(new Color(20,220,20));
         c.setFont(new Font("TimesRoman",Font.PLAIN,11));
    return c;
    where change is the value of the third column.
    Any help is highly appreciated.
    Thanx in advance.
    Regards,
    Har Krishan

    Why do you have 3 postings on this topic all made within minutes of each other? (see [url http://forum.java.sun.com/thread.jspa?threadID=574547&tstart=0]here and [url http://forum.java.sun.com/thread.jspa?threadID=574543&tstart=0]here).
    If you created a post by mistake then make a comment in the posting so people don't waste there time attempting to answer an old post.
    where change is the value of the third column.How do you know "change" is the value of the third column? Did you use a System.out.println(...) to verify this.
    A better approach is to use:
    Object o = table.getModel().getValueAt(row, 2);
    Then convert the Object to an int value and do your testing. This way you are guaranteed to be testing against the correct value.

  • InputVerifier and CellEditor - verifying JTable data

    I'm trying to verify the data in the cells of a JTable. I want to use an InputVerifier on the Component (JTextField in this case) which is in the CellEditor, so that when the user tabs through the JTable, I can stop the focus xfer when a value fails validation, and pop up an error message.
    The AbstractTableModel for my JTable contains all the information I need to validate various columns. It knows the types of data, valid ranges, etc.
    The problem I'm having is that I can't figure out a way for the CellEditor to know which column it's current cell lives in. I could assign each column it's own editor and pass the column information to the CellEditor at contruction time, but I would prefer to have a generic editor that will work for all the columns(JTable.setDefaultEditor).
    Is there a way for a CellEditor to detect which cell it is currently editing?
    Thanks.

    Hmmm that might work. I was looking for a way for the CellEditor itself to detect which cell it is editing. I guess if I gave the CellEditor a handle to the JTable it resides on, then it could ask the JTable which cell it is editing. Seems weird the CellEditor would need to ask the JTable, 'Hey what is it Im doing exactly?' but oh well.
    I'll give it a try. Thanks again.

  • Setting JTable Background Row Color based on cell Value

    I am new to Java and JDeveloper (so bear with me). I have managed to create a Swing form using BC4J (Jdev 10g preview) which contains a scrollpane with a view object represented as a table. I would like to be able to color the rows that are displayed within the table differently depending on the value of a cell/column within the row. Its not obvious to me from the property inspector how to do this - I assume it is possible as all the other bells and whistles appear to be in place.
    Thanks in advance
    Simon

    Simon,
    in Swing this is not done through properties but a custom cell renderer. You can check the Swing tutorial on http://java.sun.com for how to modify the default behavior of a JTable component. A very good book to learn Swing is "Java Swing" from O'Reilly (ISBN 0-596-00408-7).
    ADF JClient uses Swing components and therefore everything you can do in Swing you can do with JClient.
    Frank

  • How could I pass parameter that depend on values in report from report to form?

    In my case, I want to pass 'gno' and 'qno' values of report
    to form. When click on the button then the form is showed.
    There are automatically values in gno field on form so that user
    don't complete this filed.
    So I create a button on the report . I enter Javascript in
    PL/SQL Code tab in '...after displaying the footer' as follow :
    htp.formOpen
    (owa_util.get_owa_service_path||'portal30.wwa_app_module.link?
    p_arg_names=_moduleid&p_arg_values=1736929105&p_arg_names=_show_h
    eader&p_arg_values=YES&p_arg_names=GNO&p_arg_values=1&p_arg_names
    =QNO&p_arg_values=2');
    htp.formSubmit(null,'New Answer');
    htp.formClose;
    The above code can pass only static value, while I want to
    pass values that depend on value in column of report to form.
    So please tell me how can I pass this value to form. I look
    forward to hearing from all of you. Please!!!!!!
    Thank You

    Thanks for the prompt reply.
    Yes. I am using a Custom Step Type.
    I have attached a trial code which contains the trial VI, sequence and the type palette ini file.
    Please have a look at it.
    Regards,
    Mirash
    Attachments:
    Injection trial.zip ‏35 KB

  • JTable get Old Value in the Listener of change Value

    Software
    JDK 1.5 Update 6
    Requirements
    I have a JTable I want to show the sum total of certain Cell Value.So I have added a TableModelListener by which on updating the cell Value I change the total in the JTextField. The Problem is If I change the value then I have to get the previous value that the cell had. How to get that original value before the update.
    There is a way by which we can get the same by inserting one dummy column which stores previous value.But this method inserts unneccessary if you require the total of 3 columns and if you require the same thing again and again in different frames
    Is There any way by which we can show the total
    Thanks in advance
    CSJakharia

    Can I maintain a sum of a column in a JTextField such that I change the sum as soon as any value in that column is changed without recalculating the totalYes, now I understand the question you just want to update the total with the difference between the old value and the new value.
    I don't see why you are going to all this trouble. Why complicate your program, just loop though all the values in each column and add them together. You will not have a performance problem. Here is a similiar example of this approach:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=566133
    However, if you still don't like that solution then you can try overriding the getCellEditor(...) or prepareEditor(...) methods of JTable. These methods should be invoked when you start editing the cell and you could query the TableModel and save the current value.

  • Cell definitions depending on value of free characteristic

    Hello,
    I have the following requirement for one BEx query:
    Depending on the value of a free characteristic (material), values in certain cells shall be shown or not. Values in these cells are usually calculated by cell definitions. When the user selects certain materials (e.g. A1, C3) during query navigation the values in those cells have to be 0, i.e. the values that are calculatd by cell definitions should not be shown.
    When other materials are chosen by the user, those cells should show the calculated values.
    I tried to create a replacement path formula variable in order to create a 0/1-switch (find out the value of the selected material and compare it with predefined materials (A1, C3)).
    However, the value of a formula variable has to be a number. So that's no solution for my requirement.
    Do you have any ideas how to solve this requirement? Note that there is no entry variable for material.
    Thanks in advance!
    Thomas

    Hi,
    Make 3 restricted key figurs on market value restricting them with rating AAA, AA and A.
    Lets say RKF1 for rating AAA
    RKF2 for rating AA and
    RKF3 for rating A.
    Now you can use these 3 key figurs in your formula key figure which can simple be
    RKF10,4 + RKF20,3 + RKF3*0,2.
    In this way you are already sure that only one of the RKF's will have a value and depending on the rating it will be multiplied with the value you have in your logic.
    Hope this helps.
    Regards,
    Jadeep

  • JTable cell editor ..not able to delete value in the cell

    Hello,
    I have applied Cell Editor on the JTAble. I'm able to enter value initially in the cell.
    Once I tab out of that cell, go back to the same cell, edit the value again and tab out. It still shows me old value, not the updated one.
    I'm using putClientProperty("terminateEditOnFocusLost", Boolean.TRUE) to recognise the cell value without focus lost.
    Does this cause any problem ???
    Thanks in advance
    Kapil

    then what might be the problem of value not getting deleted ??
    Code is:
    public class MyTableCellEditor extends AbstractCellEditor
    implements TableCellEditor {
    //This is the component that will handle the editing of the cell value
    private JTextField component = null;
    //This method is called when a cell value is edited by the user.
    public Component getTableCellEditorComponent(JTable table, Object value,
    boolean isSelected, int rowIndex, int vColIndex) {
    component = new JTextField();
    System.out.println("value*************** "+value);
    System.out.println("Component value*************** "+component.getText());
    if(value != null){
    component.setText(value.toString());
    else{
    component.setText("");
    // Return the configured component
    return component;
    // This method is called when editing is completed.
    // It must return the new value to be stored in the cell.
    public Object getCellEditorValue() {
    return component.getText();
    public boolean shouldSelectCell(EventObject anEvent) {
    return false;
    }

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

  • JFormattedTextField as CellEditor in JTable & Enter key question

    Hi all,
    I have a cell editor (quite complicated) containing JFormattedTextField; for the description of the problem we can simplify it as:
    class Editor extends AbstractCellEditor implements TableCellEditor {
            JFormattedTextField ftf = new JFormattedTextField();
            public Object getCellEditorValue() {
                return ftf.getText();
            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                return ftf;
        }The problem is when I use this cell editor in JTable, and change the value in formatted text field and try to confirm change by Enter key, nothing happens (cursor stays in formatted text field).
    Note when I use JTextField instead of JFormattedTextField in cell editor, Enter key "confirms" new value and jumps to following cell in table (according JTable binding). So I guess JFormattedTextField "consumes" the Enter stroke in some way.
    I want to achieve the same behavior on Enter key in case of JFormattedTextField as in case of JTextField in cell editor.
    I have searched the forum, tried a lot, but was unable to find solution for such a simple problem ... probably I missed something ...
    Thanks a lot, Pepek

    The cell editor is not applied in your code (the question is what my.setCellEditor() does but it is another topic - you can find it on this forum). Use e.g.:
    public class Untitled1 extends JFrame {
        public Untitled1() {
            JPanel panel = new JPanel();
            JTable my = new JTable(5,5);
            my.setDefaultEditor(Object.class, new Editor()); //or my.getColumnModel().getColumn(0).setCellEditor(new Editor()); //just for first column
            panel.add(my);
            this.add(panel);
            pack();
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        class Editor extends AbstractCellEditor implements TableCellEditor {
            JFormattedTextField ftf = new JFormattedTextField();
            public Object getCellEditorValue() {
                return ftf.getText();
            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                ftf.setBackground(Color.YELLOW); // just to visually confirm which editor is used
                return ftf;
        public static void main(String[] args) {
            Untitled1 untitled1 = new Untitled1();
    }Therefore you couldn't find any difference - you used the same cell editor in both cases.

Maybe you are looking for

  • Obtaining comma-separated list of text values associated with bitwise flag column

    In the table msdb.dbo.sysjobsteps, there is a [flags] column, which is a bit array with the following possible values: 0: Overwrite output file 2: Append to output file 4: Write Transact-SQL job step output to step history 8: Write log to table (over

  • How can I create "Sub Queries" in a select statement?

    Hi all, I need to create reports, which are not based on a single table but on several "sub-queries". This would be the code, but I don't know how to solve that problem... SELECT OGBI.* FROM (((select "OSSRALL"."FORECAST_OWNER", sum ("OSSRALL"."TOTAL

  • What causes four beeps followed by a system shut down?

    What causes forced shut down proceed by four beeps?

  • Unable to read net files from Nikon D800

    purchased Nikon D800 have cs5 updated Adobe manager as suggested closed all adobe products Tried installing Adobe patch installer- Adobe 7.1 update,   Update Failed- not applicable for me Still cannot read NEF files,  I would like to read NEF files f

  • Warning and errors

    Below is what I get when trying to burn my project. I have one red stop sign - it's the first slide in the DVD map where it say to drag content here to automatically play. I want to do this, but can't seem to drag anything there. I have some yellow w