Last input on a JTable

Hello, I am having a "problem" with a JTable behavior about getting its data.
My problem is that the las input that reeived the JTable is not efective until I select another cell. I mean i write a serie of values and press a button, the last input on the JTable is not being recorded. Its nasty because the soft is for clients that wont take care on doing a click on any empty cell before pressing the button to handle the table data.

This question has been asked and answered dozens of times it the forum. Learn how to search the forum before posting questions:
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

Similar Messages

  • How to test to see if the cursor is on the last row in a jTable?

    I like to know how to test the cursor position in jTable.

    From the many topics you post here, I can see that you are thinking in the wrong terms.
    Although it's possible, you should not test if the current row is the last one in a JTable. Instead you should test whether or not the current row is the last one in a VO instance, to which any particular JTable's model is bound.
    So, please read the API documentation for oracle.jbo.ViewObject and oracle.jbo.server.ViewObjectImpl.

  • How can I read the last cell of a JTable that a user Enters data

    I have a one column JTable with several rows that a user enters data to. Upon entering the last data, the user clicks a button to read all the data from the rows in the JTable and puts them in an arraylist. If the user does not click enter or navigates away from the last cell, then after clicking the button it does not read the last cell entered. Since the user is clicking on a button to indicate he is done entering data on the table, does he also have to hit the enter key to indicate he is done entering the data?
    The code below is my tablemodelListener:
    public class InteractiveTableModelListener implements TableModelListener {
    public void tableChanged(TableModelEvent evt) {
    if (evt.getType() == TableModelEvent.UPDATE) {
    int row = evt.getFirstRow();
    System.out.println("Update row:"+" "+row);
    jTable1.setRowSelectionInterval(row, row);
    }

    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
    In the future, Swing related questions should be posted in the Swing fourm. (This question has been asked and answered dozens of times).
    But there is not need to repost because [Table Stop Editing|http://www.camick.com/java/blog.html?name=table-stop-editing] explains whats happening and give a couple of solutions.

  • JTable in JPanel last Column resize clips JTable doesnt repaint JPanel

    I have a JTable in a JPanel, when I drag the last column of the JTableHeader (u can see the column resizing as the text of the Table HeaderColumn moves with the drag) the JTable is outside the JPanel. Only when u click on another component and then click back on the JTableHeader does it repaint.
    I have tried jPanel.revalidate(); in the mouseDragged event of MouseMotionListener on the JTableHeader and all manner or repaints and fireTableStructureChanged. But I dont understand the order of events.
    The last bug to fix!!!
    NB I dont want to use scrollpane as its not necessary and as many tables are synchronized with one table it makes repaints less smooth
    Thanks Paul

    Well, I didn't find an answer but I did find a solution.
    The JPanel is the problem. I use it to help with layout which is not obvious in this example.
    As you can see in the code the JTable is placed in a JScrollPane which is place in a JPanel which is placed in a JTabbedPane.
    If I use Box instead of JPanel the JTable in the JScrollPane in the Box in the TabbedPane in the JFrame resizes correclty.
    So although JPanel is resizable with setSize it does not get resized when it's JFrame gets resized.
    I would still like to know why?
    ////////KBS
    JTabbedPane myTP = new JTabbedPane();
    Box myOne = Box.createHorizontalBox();
    Box myTwo = Box.createHorizontalBox();
    myOne.add(pane);
    myTP.add("One", myOne);
    myTP.add("Two", myTwo);
    ////////KBS

  • Getting the user input from a JTables Columns

    Hello
    I am having real trouble with this could someone please help?
    I have to columns on my JTable (first name , lastname).
    How can I loop though each column like this?
    the first column (first names), and get each row and add it to a String array?
    for example if the user puts in 10 firstnames I want to add all 10 to a string array.
    and for the second column, I want to add all the rows (last names ), to a arraylist. so if the user puts in 10 lastnames, I want to add them to the arraylist.
    How can I do this?
    thanks
    bobby

    JTable table = new JTable();
    TableModel model = table.getModel();
    int row = 0;
    int col = 0;
    //You can loop using the line below to get the values for each cell
    //I'm casting it as a String, if you don't have a String, you can leave
    // it as an Object
    String s = (String) model.getValueAt(row, col);

  • Can't scroll to last row in a JTable

    I am having great difficulty in getting a scrollable
    JTable to scroll to the very last row.
    I've done the following:
    int lastRowIndex = table.getRowCount() - 1;
    Rectagle rect = table.getCellRect(lastRowIndex);
    table.scrollRectToVisible(rect, 0, true));
    BUT, it always scrolls the the row just prior to
    the last... never the last. I've checked, and my
    lastRowIndex is correct. I've even tried something
    as stupid as just increasing lastRowIndex by 1,
    and it still does not work.
    So, I am at a loss as to why this does not work.
    b.c

    Moving the scroll bar to the bottom (maximum) had
    no effect. In fact, doing that alone ought to
    acheive the same goal.
    However, I have discovered that if I do either
    (move scroll bar or set viewport to last cell's
    rectangle) TWICE, it works.
    I speculate that there is some kind of latency
    in the GUI "knowing" what the maximum extent really
    is. Trying to move to the end the first time fails,
    but it does cause the GUI to refresh itself
    immediately afterwards so that if I try this a
    second time, it works.
    I can achieve the same results if I simply
    ***force a re-paint before attempting to move
    the the last cell***. Then, it works.
    So, my solution was to do the following:
    __ int lastRowIndex = myTable.getRowCount() - 1;
    __ if (lastRowIndex > -1)
    _____ // repaint the window first.
    _____ Rectangle bounds = getBounds();
    _____ bounds.x = 0;
    _____ bounds.y = 0;
    _____ paintImmediately(bounds);
    _____ // Now, move to the last row
    _____ bounds = myTable.getCellRect(lastRowIndex, 0, true);
    _____ myTable.getScrollPane().getViewport(
    _____ ).scrollRectToVisible(bounds);

  • Restricting user to input a maximum number of characters in a JTable cloumn

    Hi all,
    I'me developing a program which should restrict the user with a maximum number of characters input in a JTable column. It should show a msg and restrict the user from typing in, if the number of characters exceed the limit and on clicking cancel it should revert back the changes made to the field.
    Can anybody please help me?
    Thanks in advance,
    Amol

    Hi,
    Try to write your own cell editor.
    There attach an InputVerifier to the JTextField of the editing cell.
    The input verifier can watch for the size of the input and if too many characters you can show a JOptionPane.Dialog.
    Olek

  • Can I disable forward TAB when focus is in last JTable column

    I am new to Swing. My boss hates the fact that when the focus is in a cell in the right most column, when you press TAB, it wraps to the beginning of the next line. He wants the behavior to be that a TAB from the last column stays right where it is. This must be a simple question but I have been searching and haven't found the place with the answer.
    Thank you.

    Thank you, V.V., I didn't realize that the two issues were related.
    Previously, you wrote:
    Override the processKeyBinding method in a class that extends JTable. This method traps every keyevent (including those generated by menu accelerators, so be sure to build procedures to do something with them or ignore them so you don't double up on the processing of those keys). Find out which key you can to use for navigating around the table and do something with those keys. For the rest of the keyevents, check to see if it is a type KeyEvent.KEY_TYPE, if so the KeyboardFocusManager to displatch the event to your JDialog.
    ;o)
    V.V.
    If I understand your reference to your previous answer, I need to trap the TAB KeyEvent and if I am in the last column of the JTable, I should make sure that I stay where I am. Am I understanding you correctly ?
    thank you for your patience,
    W.W.

  • How to remove the last line input into a string indicator??

    I am currently working on a program where the user has the ability to create a profile for one of our lab machines to run.  When the user selects what parameters they would like, a string indicator shows the user the last input they set followed by a comma.  For example, if the user selects which profile they want, and the times they would like to set, the following string would be displayed:
    As you can see in the picture above, the profile is updated in the string indicator after every set button is hit.  In the event the user makes a mistake, I want them to have the ability to delete the last line that was added.
    This is the code I developed so far.  The string coming in and leaving is attached to a shift register so it continues to append to the indicator.  I tried in this case to count how many lines have been written in the string so far, and I built an array with the current string.  Using the delete from array.VI I indexed it to the number of lines that was created so that the last line is deleted.  I unfortunately had no luck.  Any suggestions?

    tbob wrote:
    Fonzie1104 wrote:
    Hey Tbob,
    That almost worked.  The only issue though is it leaves a null string in its place without moving everything after up one line.  Also, if i have a parameter repeating multiple times, it doenst seem to work.
    I'm confused.  If you are deleting the last line, how can there be anything after?  What do you mean by a parameter repeating multiple times?
    If you look at my example front panel, you will see that the last line is deleted.  Isn't this what you asked for?
    It's due to the fact that your constant doesn't have a comma in the last line. If you add that in, you should be able to reproduce his problem. This is just a guess though, I didn't actually test it to see.
    Message Edited by for(imstuck) on 06-08-2010 01:24 PM
    CLA, LabVIEW Versions 2010-2013

  • Restricting JTable Character Input

    I wish to limit the input of a JTable column to digits only. I have done this with JTextfields, but I cant figure how to apply that to tables.
    Can anyone point me to example code or tutorials which show how this is done for JTable cells?
    Many thanks in advance.

    The Swing tutorial has a section on JTables. It gives an example on how to restrict a column to numeric values only. Best of all it reuses the Custom Document that you used for your JTextField.
    file:///C:/Java/tutorial/uiswing/components/table.html#validtext

  • Transfer Data from a JTable to the table model

    Hi
    I' looking for a simple method to transfer the last user input in a table to the table model.
    For example:
    In a Dialog the user insert in a JTable a few values and leaves with OK. But the last input is not saved in the model. It is just saved after selecting a new field in the JTable before leaving the Dialog.
    Is there a call to transfer all input to the model?
    Thanks
    Guido

    class MyJTable extends JTable (
    public boolean validateInput() {
    if(isEditing()) {
    return cellEditor.stopCellEditing();
    return true;
    Call this method whenever you want the input value to be stored in the table model. The return value can be false if the input isn't valid, this will depend on the cell editor.
    The idea is:
    Ask if the table has an editor activated. (isEditing())
    If so, request the editor to store the value in the model.
    I haven't prouved the code, sorry, but I hope you get the idea and helps.

  • Problem with JPanel, JScroll and JTable

    Hi.
    On one of my Jframes, i have 3 Jpanels. There are two on one side, and one of the other which spans the height of the other two. However, it does more than span the height of the other two, it streches the height of the Jframe as it is about 300 pixels too heigh.
    I'm not sure which element is streching the JPanel, it might be either the Jpanel itself, the JScroll or the JTable. Theres alot of code, however i'm going to try and cut out the irrelevent parts.
    I call the Jpanel via:
    FarmList = new javax.swing.JPanel();
    FarmList.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Farm List", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11)));
    FarmList.add(new GetFarms());And the code for the GetFarms() class is:
    public class GetFarms extends JPanel {
         private final int COLUMNS = 4;
         private int ROWS = 2;
         private JTable sampleJTable;
         private String[][] cells = new String[ROWS][COLUMNS];
        public static void main(String[] args) throws Exception {
            JFrame frame = new JFrame("Covenant Farm List");
              frame.add(new GetFarms());
            frame.setSize(450,150);
            frame.setVisible(true);
         public GetFarms() throws Exception {
              URL theUrl = new URL("http://www.allydm.co.uk/Covenant/farm_list.php");
              BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        theUrl.openStream()));
              String inputLine = in.readLine();
              String[] lines = inputLine.split("<br>");
              for (int i = 0; i < ROWS; i++) {
                   String[] stuff = lines.split(" ");
                   for (int j = 0; j < COLUMNS; j++) {
                        cells[i][j] = stuff[j];
              in.close();
              String[] columnNames = {"Username", "DA", "Sentry", "Last Update"};
              sampleJTable = new JTable(cells, columnNames);
              JScrollPane tablePane = new JScrollPane(sampleJTable);
    add(tablePane, BorderLayout.CENTER);
    If anyone has any ideas, on how to limit the size of the Jpanel or JScroll it'd be greatly appreciated.

    did you implement setxxxSize() methods?
    see
    http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html

  • How can I change the default process of VK_ENTER in JTable

    Now I have met a requirment to process the "enter" key event in JTable. But it is found that the JTable has a default process on the ENTER key press, and it will select the next row. Even the worse, the default process is invoked before the KeyListener I registered.
    How can I remove that?
    I have tried the follow ways: 1.remove several keys, such as "selectNextRow","selectNextRowExtendSelection", from the actionMap,
    2.invoke processKeyBinding() in the constructor of my subclass of JTable.
    But both lead to failure.
    And I can't find the default process to the VK_ENTER in the java source code. I need help on this.
    BTW, does anyone know how to eliminate the focus traversal between cells. When I press left arrow or right arrow, the focus traverses in the scope of the selected row.

    thanks
    i also found solution for my poblem:
    i have this code:
    jMenuItem jMnItEdit;
    jMnItEdit.setAccelerator( KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0));
    also i had ActionListener bounded to this JMenuItem
    but Ialso had in form JTable and it always grabbed my VK_ENTER event and that menu item wasn't working at all
    but when i overrode that input map for JTable and set
    tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), "none");
    everything started to work perfectly,
    thanks a lot

  • Problem with get_attribute for a new input field in ICWebclient

    Hi experts,
    I have an issue in ICWebClient.
    I have copied the stnd tcode and CRM_IC and added my own view with 5 fields.
    I will enter a value in the name field in that layout and click CONTINUE button. It will take me to other page.In this page there is a button EDIT, when i click this EDIT button it will take me back to firstpage where i created my layout. Now I want to display the previous value i entered in the last input box.
    In the Controller class in the SET_MODELS method i  have written this code,
    view->set_attribute(name = 'legal' value = lr_mycontext->z911home->NAME).
    and in the my view, i am writing this code,
    view->get_attribute( exporting name = 'legal' importing value = lr_mycontext->z911home->NAME).
    But My complete view is not displaying. Its giving me the error.
    I hope u have understood my issue.  I need to keep my value in the input box even if i come to the same field.
    Kindly help me what is the best approach for this. I need to do this and i m trying for so long. Points will be awarded highly..
    regards,
    NtK.

    thanks

  • How to insert new row in JTable?

    In my application,I have a jTable. And the form dose not have a Nevigation bar.
    After I retrieve a record into the jTable, I want to add a new row after the retrieved record. But I could not create a new row by pressing the down key at the last row of the jTable(I could do that in Oracle Form). Dose jTabel have such feature as that in Oracle Form? Or I can do that in another way?

    Such a feature is not available, but you could add a key event handler which works its magic when it detects a press on the down arrow key, while the last row is selected. Then you can perform the code to insert a new row.

Maybe you are looking for

  • Can Not Use Air Disk for Time Machine Backup

    I have my Lacie 750 GB drive plugged into my AEBS, and it shows up on my network. I can not get Time Machine to recognize it so I can backup. I would appreciate any specific setup info. anyone has that can fix this problem. Thanks - Dudley Warner

  • How to Create a Webservice in XI( V. Urgent)

    Hi, How to create a Web service in XI  .. Points will be awarded for the answer, Regards, Jayasimha

  • Wireless Controller with 802.1x

    Hi. This may seem like a stupid question, but if i'm using 802.1x on my wireless network and using RADIUS/LDAP/ACS for authentication, do I need to configure any aaa commands on my access switches? It was my understanding that all traffic from the cl

  • Set Padding Color

    Hi,      Is it possible to set color for padding . For example we are setting paddingTop=2 and we may get 2 pixel gap. Is it possible to fill the 2 pixel gap by color.If so please give me a sample. Regards, Jayagopal.

  • How to view logs of disabled MAC addresses?

    I have a Wireless LAN Controller 4402 and WCS 7.0, and I have a few MAC addresses that are "disabled" due to policy violations. How can I view a log or a report that will show me if these MAC addresses are still attempting to connect?