Update jtable cell via numeric keypad

Hi,
I have a problem, trying to figure out how to input numbers in a jtextfield in a jtable cell, from a group of jbuttons (rendered as a numeric keypad). I can get the cell to focus, but when I click on one of the jbuttons in the keypad, the cell loses focus and nothing is printed. I can update the cell by directly typing from the keyboard; that works fine. But I'm lost when trying to do it from the touch-screen keypad. Can anyone point me in the right direction. I assume I need to attach additional listeners somewhere.
Thanks in-advance.
Lee

I can get the cell to focus, Then the code for you button would need to be something like:
String text = (String)table.getValueAt(...);
String updated = text + button.getText();
table.setValueAt(updated, ...);

Similar Messages

  • Update JTable cells via setValueAt

    Hello all,
    I'm trying to implement a setValueAt method using an arrayList.....no success.What listeners should I have set up(For JTable or my table model)? I am new at this and I'm trying to update the JTable cells after a query from some db. Could anyone help?
    When trying to change the a value in the table I get these errors:
    "Exception occurred during event dispatching:
    java.lang.ClassCastException: java.lang.String
    at CachingResultSetTableModel.getValueAt(CachingResultSetTableModel.java:37)
    at javax.swing.JTable.getValueAt(JTable.java:1711)
    at javax.swing.JTable.prepareRenderer(JTable.java:3530)"
    public void setValueAt(Object avalue, int r, int c){
    if(r < cache.size()){
    row[c] = (Object[])cache.set(r, avalue);
    fireTableCellUpdated(r, c);
    }//setValueAt
    *********For reference here's the getValueAt method*************************
    public Object getValueAt(int r, int c){
    if(r < cache.size()){
    row = (Object[])cache.get(r);
    return row[c];
    else
    return null;
    }//getValueAt

    I would think that everone who starts off with JTable will have a couple of concept problems. I am also going thru this learnig curve. It looks to me ( the blind leading the blind etc) like your basic table has strange data in it. The problem is occuring when the JTable is trying to setup the data from the table model.
    I don't think its anything to do with setValueAt.
    I kept going back to TableMap, TableSorter and JDBCAdaptor examples and copying the code from them to come right.> I debug by putting a System.out .... in all the methods until I get to where the code is giving trouble.
    Good luck [email protected]
    Hello all,
    >
    I'm trying to implement a setValueAt method using an
    arrayList.....no success.What listeners should I have
    set up(For JTable or my table model)? I am new at
    this and I'm trying to update the JTable cells after a
    query from some db. Could anyone help?
    When trying to change the a value in the table I get
    these errors:
    "Exception occurred during event dispatching:
    java.lang.ClassCastException: java.lang.String
    at
    CachingResultSetTableModel.getValueAt(CachingResultSetT
    bIleModel.java:37)
    at javax.swing.JTable.getValueAt(JTable.java:1711)
    at
    javax.swing.JTable.prepareRenderer(JTable.java:3530)"
    public void setValueAt(Object avalue, int r, int c){
    if(r < cache.size()){
    row[c] = (Object[])cache.set(r, avalue);
    fireTableCellUpdated(r, c);
    }//setValueAt
    *********For reference here's the getValueAt
    method*************************
    public Object getValueAt(int r, int c){
    if(r < cache.size()){
    row = (Object[])cache.get(r);
    return row[c];
    else
    return null;
    }//getValueAt

  • JTable cell only numerical

    Hello,
    it`s possible in cell of a JTabel th context only numerical or letters. Is there any function for this?
    Thanks for any answer or tip!!!

    JTable can use custom editors: see the tutorial, and particularly:
    + [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html]How to Use Tables
    |---...
    |--- [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#validtext]Using an Editor to Validate User-Entered Text
    |---...
    |--- [url http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html]How to Use Formatted Text Fields
    |---...

  • Update JTable - Cell

    i tried out the sample http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/TableDemo.java. if i enter a new value and klick into another cell of the table all works fine. if i click on the table header after editing the cell the old value appears in the cell. if i enter signs directly after the click on the table header the text appended to the old value of the edited cell.
    i hope, anybody can help me.

    Hmm, the suggestion given above appears to work when focus is gained on all other components, so the table header must have to logic to "cancel" cell editing. You can add your own MouseListener to "save" the edited data to the table header:
    table.getTableHeader().addMouseListener( new MouseAdapter()
         public void mousePressed(MouseEvent e)
              JTableHeader header = (JTableHeader)e.getSource();
              JTable table = header.getTable();
              if (table.isEditing())
                   table.getCellEditor().stopCellEditing();
    });

  • Indeterminate JProgressBar inside JTable cell

    I am able to put a JProgressBar inside a JTable cell, via a custom renderer to do so, however, I am unable to make the progress bar show the indeterminate animation. Any ideas? I calledbar.setIndeterminate( true ); and it doesn't seem to want to show. Is the JTable preventing it?
    (should I include more of my code?)

    Your JProgressBar is used to render the table cell only when that cell of the JTable needs to be rendered and the JProgressBar has no say in this.
    I don't know why you would want to do this but to do this I would set up timer that fired a tree model event to say that the content of the cell had changed. This would trigger the cell to be re-painted. I think, but I can't be sure, that you will not be able to use
    bar.setIndeterminate( true );
    You may have to craft your own progress bar to make this easy.

  • Alfa numerical keypad issue after fp2 update: spe...

    in fp2 update in alfa numerical keypad predictive text tab has been given at the top of keypad. But nokia has forgot to develop that text box where we need to type has to shift by that much height accordingly. So as a result of that we need to type blindly. Please give your feedback on this so nokia has to fix it immediately. Also lef.and right arrow has been made temporary after ye tap at text box. But it's not working properly. And also not working in all application.these are the biggest blunder in this software update.nokia fix it.immediately.

     Nokia have pulled the FP2 update due to numerous bug reports and complaints, so are aware of certain issues and a fix should be provided in the future.
    Ray.

  • My Logitech K750 numeric keypad stopped working after last update-numbers only

    After the last Mountain Lion update, the number on my numeric keypad will not function.  They work for my login, but then become inactive.  I have tested the system with an Apple keypad, same thing!  What happened?  Is there a keyboard setting that needs to be reset?

    Dianefromblaine,
    Thank you.  My K750 number pad stopped working on my iMac.  The keyboard and number pad 'do' work on a different Mac, so I suspect it is some setting on the iMac.  I did a Safe Mode start, reset the SMC, and repaired the disk permissions.  The dongle was plugged into an USB Hub.  It is now plugged into the iMac USB port.  The keyboard has a 90% charge, but still does not work.  Then suddenly it started working again, but stopped after about one month. 
    I found your "Accessibility>Mouse and Trackpad" suggestion and deselected "Enable Mouse Keys".  My number pad works again.
    Thanks.

  • Numeric keypad cursor movement keys no longer work in Firefox

    In any text box, on any web page, plus in the address bar, plus in the search box, the numeric keypad cursor movement keys (home, end, up, down, left, right) no longer work
    NUMLOCK is off
    SCROLLLOCK is off
    The regular cursor keys, plus home, end etc.all work fine
    The numpad keys work fine in other applications (e.g. textpad, notepad, word, openoffice etc.)
    This only affects navigation in a text box
    I am running windows, and just to make sure, I backed out the last windows update and restarted my pc - problem still exists
    I have tested with a different keyboard via USB, problem still exists
    I tried restarting firefox in safe mode, problem still exists
    OS Windows 7 Home Premium SP1, latest update is KB2952664
    Firefox 29.0.1

    You can check for issues caused by one of the installed and enabled extensions.
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem.
    *Switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance
    *Do NOT click the Reset button on the Safe Mode start window
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Presario numeric keypad not working

    I've had a Presario CQ61-422 for about 18 months but never bothered with the numeric keypad before. Recently my daughter came round and borrowed the machine and she is used to entering numbers via the pad. Pressing the NumLock key gives a high pitch beep and turns the indicator light on but has no effect on the keypad - each one still acts in the navigation mode. Pressing NumLock again switches light off with low pitch beep but no difference to key functions.
    I've updated the BIOS from F.20 (when purchased) to F.23 to no effect. I'm satisfied there is no physical malfunction to the keys but can't understand why they won't toggle between navigation and numeric entry. I've not played with any other system settings since purchase just used it out of the box as setup by HP. Anyone had a similar experience?
    OS is Win7 home premium 64
    This question was solved.
    View Solution.

    At last fixed the problem. I found out that Mouse Keys had been set on allowing direction arrow keys to move mouse pointer. Switched this feature off and Num Lock keys all now do what they should.
    Case closed.

  • How can I use my iPhone 4 as a numeric keypad for my ipad?

    I am a teacher that uses my ipad for entering and keeping tracks of grades.  The one thing that would make this perfect, is if I could use my iPhone as a numeric keypad.  I have found many ways to use the iPhone/ipad as a keypad with a PC but not ipad.  There must be a way.....they sync/talk to each other all the time.  HOW? 

    I read it and I do have a hot spot I use it for my laptops inter net but I want to know if I can by use of my phones USB  connection use it as a dongle. My laptop doesn't have the bluetooth hardware I need to update the software in my cars hands free kit it's downloaded in my PC but no way to install without bluetooth.  What I'm trying to do is . 
    Labtop+USB +iPhone bluetooth to bluetooth +car kit.  Is there an app I need  or can I configure it on my PC
    My service provider is AT&amp;T

  • How to write an element in a  JTable Cell

    Probably it's a stupid question but I have this problem:
    I have a the necessity to build a JTable in which, when I edit a cell and I push a keyboard button, a new Frame opens to edit the content of the cell.
    But the problem is how to write something in the JTable cell, before setting its model. Because, I know, setCellAT() method of JTree inserts the value in the model and not in the table view. And repainting doesn't function!
    What to do??
    Thanks

    Hi there
    Depending on your table model you should normally change the "cell value" of the tablemodel.
    This could look like:
    JTable table = new JTable();
    TableModel model = table.getModel();
    int rowIndex = 0, columnIndex = 0;
    model.setValueAt("This is a test", rowIndex, columnIndex);
    The tablemodel should then fire an event to the view (i.e. JTable) and the table should be updated.
    Hope this helps you

  • Hi. I have a ipod touch 4th generation, it's in perfectly good condition no cracks or anything. The issue is my ipod is locked and i'm not able to type in my passcode because the numeric keypad isn't working properly.Also my home button isn't working.

    Hi. I have an ipod touch 4th generation, it's in perfectly good condition no cracks or anything. The issue is my ipod is locked and i'm not able to type in my passcode because the numeric keypad isn't working properly.For ex. when i hit 8 (which is the second number in my passcode) the number 5 type in. Also my home button isn't working. Hope that was specfic enough.. thanks!!

    Place the iOS device in recovery mode with one of thes programs and then restore via iTunes
    For PC
    RecBoot: Easy Way to Put iPhone into Recovery Mode
    If necessary:
    Download QTMLClient.dll & iTunesMobileDevice.dll for RecBoot
    For MAC or PC       
    The Firmware Umbrella - TinyUmbrella
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings        
    For how to restore:
    iTunes: Restoring iOS software
    To restore from backup see:
    iOS: How to back up     
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:

  • Problem in event handling of combo box in JTable cell

    Hi,
    I have a combo box as an editor for a column cells in JTable. I have a event listener for this combo box. When ever I click on the JTable cell whose editor is combo box,
    I get the following exception,
    Exception occurred during event dispatching:
    java.lang.NullPointerException
         at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.setDispatchComponent(Unknown Source)
         at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.mousePressed(Unknown Source)
         at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Can any one tell me how to over come this problem.
    Thanks,
    Raghu

    Here's an example of the model I used in my JTable. I've placed 2 comboBoxes with no problems.
    Hope this helps.
    public class FileModel5 extends AbstractTableModel
    public boolean isEditable = false;
    protected static int NUM_COLUMNS = 3;
    // initialize number of rows to start out with ...
    protected static int START_NUM_ROWS = 0;
    protected int nextEmptyRow = 0;
    protected int numRows = 0;
    static final public String file = "File";
    static final public String mailName = "Mail Id";
    static final public String postName = "Post Office Id";
    static final public String columnNames[] = {"File", "Mail Id", "Post Office Id"};
    // List of data
    protected Vector data = null;
    public FileModel5()
    data = new Vector();
    public boolean isCellEditable(int rowIndex, int columnIndex)
    // The 2nd & 3rd column or Value field is editable
    if(isEditable)
    if(columnIndex > 0)
    return true;
    return false;
    * 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();
    * Retrieves number of columns
    public synchronized int getColumnCount()
    return NUM_COLUMNS;
    * Get a column name
    public String getColumnName(int col)
    return columnNames[col];
    * Retrieves number of records
    public synchronized int getRowCount()
    if (numRows < START_NUM_ROWS)
    return START_NUM_ROWS;
    else
    return numRows;
    * Returns cell information of a record at location row,column
    public synchronized Object getValueAt(int row, int column)
    try
    FileRecord5 p = (FileRecord5)data.elementAt(row);
    switch (column)
    case 0:
    return (String)p.file;
    case 1:
    return (String)p.mailName;
    case 2:
    return (String)p.postName;
    catch (Exception e)
    return "";
    public void setValueAt(Object aValue, int row, int column)
    FileRecord5 arow = (FileRecord5)data.elementAt(row);
    arow.setElementAt((String)aValue, column);
    fireTableCellUpdated(row, column);
    * Returns information of an entire record at location row
    public synchronized FileRecord5 getRecordAt(int row) throws Exception
    try
    return (FileRecord5)data.elementAt(row);
    catch (Exception e)
    throw new Exception("Record not found");
    * Used to add or update a record
    * @param tableRecord
    public synchronized void updateRecord(FileRecord5 tableRecord)
    String file = tableRecord.file;
    FileRecord5 p = null;
    int index = -1;
    boolean found = false;
    boolean addedRow = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord5)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    { //update
    data.setElementAt(tableRecord, index);
    else
    if (numRows <= nextEmptyRow)
    //add a row
    numRows++;
    addedRow = true;
    index = nextEmptyRow;
    data.addElement(tableRecord);
    //Notify listeners that the data changed.
    if (addedRow)
    nextEmptyRow++;
    fireTableRowsInserted(index, index);
    else
    fireTableRowsUpdated(index, index);
    * Used to delete a record
    public synchronized void deleteRecord(String file)
    FileRecord5 p = null;
    int index = -1;
    boolean found = false;
    int i = 0;
    while (!found && (i < nextEmptyRow))
    p = (FileRecord5)data.elementAt(i);
    if (p.file.equals(file))
    found = true;
    index = i;
    } else
    i++;
    if (found)
    data.removeElementAt(i);
    nextEmptyRow--;
    numRows--;
    fireTableRowsDeleted(START_NUM_ROWS, numRows);
    * Clears all records
    public synchronized void clear()
    int oldNumRows = numRows;
    numRows = START_NUM_ROWS;
    data.removeAllElements();
    nextEmptyRow = 0;
    if (oldNumRows > START_NUM_ROWS)
    fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);
    fireTableRowsUpdated(0, START_NUM_ROWS - 1);
    * Loads the values into the combo box within the table for mail id
    public void setUpMailColumn(JTable mapTable, ArrayList mailList)
    TableColumn col = mapTable.getColumnModel().getColumn(1);
    javax.swing.JComboBox comboMail = new javax.swing.JComboBox();
    int s = mailList.size();
    for(int i=0; i<s; i++)
    comboMail.addItem(mailList.get(i));
    col.setCellEditor(new DefaultCellEditor(comboMail));
    //Set up tool tips.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for mail Id list");
    col.setCellRenderer(renderer);
    //Set up tool tip for the mailName column header.
    TableCellRenderer headerRenderer = col.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the Mail Id to see a list of choices");
    * Loads the values into the combo box within the table for post office id
    public void setUpPostColumn(JTable mapTable, ArrayList postList)
    TableColumn col = mapTable.getColumnModel().getColumn(2);
    javax.swing.JComboBox combo = new javax.swing.JComboBox();
    int s = postList.size();
    for(int i=0; i<s; i++)
    combo.addItem(postList.get(i));
    col.setCellEditor(new DefaultCellEditor(combo));
    //Set up tool tips.
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for post office Id list");
    col.setCellRenderer(renderer);
    //Set up tool tip for the mailName column header.
    TableCellRenderer headerRenderer = col.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer)
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the Post Office Id to see a list of choices");
    }

  • Way to listen for change in JTable cell?

    I am having troubles trying to catch a key event while the user is entering text inside a given JTable cell (x/y location). The JTable only seems to manage String objects in it's cells so I can't place a JTextField in there with a KeyListener on it.
    Currently, I can only get control of the application once the user has left the cell they are editing.
    Does anyone have an example of a JTable 'cell KeyListener' scenario? At this point I want to see if I can print 'hello world' each time I type a character within a cell. Then I'll go from there....

    If you want to know when the contents of a cell have been updated you should use a TableModelListener.
    If you want to know when a character is added/removed from the cell editor then you need to first understand how this works with a simple text field.
    Typically you would use a DocumentListener to receive notifies of a change to the text field. However, within the DocumentEvent you wouldn't be able to change the text field as this notification comes after the text field has already been updated.
    If you need to ability to intercept changes to the text field before they happen, then you would need to use a DocumentFilter. An example of using a DocumentFilter is given in the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#filter]Text Component Features.
    Once you get your regular text field working the way you want, the next step to create a DefaultCellEditor using this JTextField and use this editor in your JTable. The above tutorial also has a section on using editors in a table.

  • Updating JTable Contents

    I'm having trouble refreshing a JTable after changing it's 2D Object array data. Perhaps this is a stupid question, but any advice would be appreciated.
    Basically I've been building from the SimpleTableDemo.java file in the "How to Use Tables" tutorial. I set Object[][] data to a 2D Object array that is modified by other parts of my program.
    I added the public void tableChanged(TableModelEvent e) function to detect data changes, displaying a simple System.out, but it never seems to get called.
    Is there any way that the JTable can observe changes in the Object[][] data array and update it's self accordingly? I'm never sure if rows are being added or removed.
    I hope that made sense, and thank-you in advance to anyone who replies.
    -Arthur

    Couple of things...
    Whenever you change the contents of your TableModel you need to fire the appropriate event to get the JTable to update the viewed rows... in your case it sounds like you would have to call the "fireTableDataChanged()" method defined by AbstractTableModel so that your contents will be viewed.
    Also... it is rare that you really need to update the entire contents of your table model, most the time it is more efficient to just update the cell or row your need and call the appropriate "fire..." method to update
    Hope this helps
    Josh Castagno
    http://www.jdc-software.com

Maybe you are looking for

  • Error while pushing idocs from SAP to XI

    Dear All, For doing ALE configurations for pushing IDOC's from SAP to XI, I am following the following blog posted on SDN: /people/swaroopa.vishwanath/blog/2007/01/22/ale-configuration-for-pushing-idocs-from-sap-to-xi I am able to create the  model v

  • Using [TODAY] in filtered views

    The instructions under the filter section in Edit View clearly states; "Show all of the items in this view, or display a subset of the items by using filters. To filter on a column based on the current date or the current user of the site, type [Toda

  • Logic or GarageBand will not load.

    Both logic and garageband will not load. They begin to load then shut down. Logic gets to the core audio portion of the load and stops. I get similar error msgs for both programs, and they both say there is a problem with plugins rewire for melodyne,

  • Weird hyphenation problem

    I'm using InDesign CS3 5.0.4 on a MacBook running OS10.5.8 I have an InDesign document that I need to convert to Microsoft Word. Before copying the InDesign text I turn off hyphenation. However, when I paste the text into the Word document, all kinds

  • What's it called?

    OK I feel really dumb. I forgot what to call it. you know when the playhead goes all the way to the end of the arrange window, then the arrange window jumps to the next page, or should I say follows the playhead. mine stopped doing it so I must have