How do I set the value of a cell in a Jtable to be only the last character entered when clicking off of it?

jwm197

I am trying to make it so that when the user clicks off the cell they are editing in a JTable the contents of the cell is set only to the last character entered. To achieve this I have a method that returns a new JTable with an anonymous class overriding the editingStopped method. Right now this is producing 2 errors: The first being that it won't display the updated string in the cell and secondly the lastChar variable is being set to the last character that was in the cell prior to the cell being click on. Here is my code:

 private JTable makeTable() {
        String data[][] = { 
                { "Move Down", "hello" }};
        String[] headers = { "Action", "Button" };
        return new JTable(new DefaultTableModel(data, headers)) {
            @Override
            public boolean isCellEditable(int row, int column) {
                return column == 1;
            }

            public void editingStopped(ChangeEvent e) {
                String lastChar = getValueAt(getEditingRow(), 1).toString().substring(
                        getValueAt(getEditingRow(), 1).toString().length() - 1);
                        setValueAt(lastChar, getEditingRow(), 1);
                System.out.println("Row " + (getEditingRow()) + " edited");
                System.out.println("Cell set to:" + lastChar);

            }
        };
    }
jwm197

This can be solved with calling the super method as it wasn't leaving the cell properly creating issues.

public void editingStopped(ChangeEvent e) {
                int row=getEditingRow();
                System.out.println("Row " + (getEditingRow()) + " edited");
                super.editingStopped(e);
                
                String lastChar = getValueAt(row, 1).toString().substring(
                        getValueAt(row, 1).toString().length() - 1);
                setValueAt(lastChar, row, 1);
                System.out.println("Cell set to:" + lastChar);

            }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I set up a function that displays a set vector only when 3 is entered?

How do I get an element to re-set Attribute value when clicking self as well as when clicking other buttons?

How do I remove rows based off of cell value? - SQL

WPF How to change the entered character when clicking on the textbox?

How can I remove only the last single character not the entire value?

How do I allow only a comma to be last character

How do I Divide Values in a Column by the Value in the Last Cell?

How can I get the value from a cell when clicking other cell in the row?

How to delay cell protection when value is entered in a cell?

How do I mutate a list-column to a common one leaving only the last value when there is a vector in the list?

How do I chop/slice/trim off last character in string using Javascript?

What should I do to print only the last data entered in Text?

How do I create rows in a table based off a cell value and fill a column also based off the cell values in Excel

How do I prevent the onClick of the parent going off when clicking the child?

How do I turn off the annoying clicking sound when browsing web pages in Internet Explorer?

How do I execute instructions only if the cell value change?

while( cin >> value ) breaks the loop when i entered a character

How can I get only the first character entered by the user?

DataTables - How do I get/set the value of a cell in a row?

How to set value of the Text filed equal to the JTable cell

How do I set a value to be the same as in the last item?

How do I get ahold of my cell when clicking in collectionView using rx?

How do I remove the bottom cell border line from entire row when clicking a shape?

Not getting last updated value in Jtable Cell

How do I set the value of the selected WPF DataGrid cell to the value of the cell above?

How do I get Min and max values to only print when "year" is entered?

How do I make the ::before tag only appear when content is entered?

How do I get the last id entered with Dapper?

How do I get the last character of a string?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive