Results 1 to 2 of 2
  1. #1
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default JTextfield renderer/editor input map

    Can I put inputmap at JTextField that is use as a renderer and editor in JTable? I am trying to bind a
    enter key at editText, when the user press enter key then the cursor will transfer to the next editText
    (next column in JTable).


    Please see the sample code.
    Java Code:
        protected class JTableText extends AbstractCellEditor implements
                TableCellRenderer, TableCellEditor
        {   private JTable table;
            private int row;
    
            private JTextField renderText;
            private JTextField editText;
            private String text;
    
            public JTableText(JTable table, int column)
            {   this.table = table;
    
                renderText = new JTextField();
                editText = new JTextField();
    
                editText_Properties();
    
                TableColumnModel columnModel = table.getColumnModel();
                columnModel.getColumn(column).setCellRenderer( this );
                columnModel.getColumn(column).setCellEditor( this );
            }
    
            public int getRow()
            {   return this.row;    }
    
            @Override
            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
            {   this.row = row;
                text = (value == null) ? "0" : value.toString();
                editText.setText( text );
                return editText;
            }
    
            @Override
            public Object getCellEditorValue()
            {   text = (editText.getText() == null) ? "0" : editText.getText().toString();
                txtTotalQty.setText(Integer.toString(computeTotalQty()));
                return text;
            }
    
    //  Implement TableCellRenderer interface
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
            {   if (isSelected)
                {   renderText.setForeground(table.getSelectionForeground());
                    renderText.setBackground(table.getSelectionBackground());
                }
                else
                {   renderText.setForeground(table.getForeground());
                    renderText.setBackground(UIManager.getColor("Button.background"));
                }
    
                renderText.setText( (value == null) ? "0" : value.toString() );
                return renderText;
            }
    
            private void editText_Properties()
            {   ActionMap enterAction = editText.getActionMap();
                enterAction.put("enter_key", new AbstractAction()
                {   public void actionPerformed(ActionEvent e)
                    {   //?? [b]I dont know what to put here.[/b]
                        
                    }
                });
            }
        }
    Thanks,
    geje

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Anyone there that can help me? Is this impossible? Is there other way I can do this?

    Thanks,
    geje

Similar Threads

  1. input masking 24hour time format (hh:nn) to jTextField
    By newbiejava in forum New To Java
    Replies: 2
    Last Post: 07-24-2010, 02:12 PM
  2. Replies: 1
    Last Post: 07-19-2010, 01:31 AM
  3. Replies: 7
    Last Post: 04-10-2010, 12:31 PM
  4. Convert Input from JTextField to int?
    By jls7168 in forum New To Java
    Replies: 7
    Last Post: 02-20-2009, 03:29 AM
  5. Constraining Input in JTextField
    By kataya in forum AWT / Swing
    Replies: 1
    Last Post: 06-26-2008, 07:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •