1

I have problem with JTable. I need to edit some row, but when i finish and press ENTER, i want change action like save in Database. This is my code:

// JTable PDV
    tablePDV = new JTable(pdvTableModel) {
        // Editable Enable || Disable
        public boolean isCellEditable(int rowIndex, int colIndex) {
            if (check == true) {
                if (rowIndex == rowSelectedIndex
                        && colIndex == colSelectedIndex) {
                    return super.isCellEditable(rowIndex, colIndex);
                }
            }
            return false;
        }
    };

    tablePDV.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseExited(MouseEvent arg0) {
            tablePDV.clearSelection();
            tablePDVSecond.clearSelection();
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            tableMousClick(tablePDV, e, 436, 455, 477, 498, 1);

        }
    });
kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • Have you tried to do this and failed? It usually helps on SO if you can show something you have tried and then people can help you get it to where you want it to be. For example, you might include source code of how you tried to modify your use of JTable to get the desired behavior. – Gordon Seidoh Worley Jun 10 '13 at 04:55
  • This is my first post and I have changed. – Sinan Dizdarević Jun 10 '13 at 10:03
  • See if this possible duplicate of [JTable enter key](http://stackoverflow.com/questions/9091208/jtable-enter-key) helps. – trashgod Jun 10 '13 at 17:09
  • @trashgod tnx, but that was not answer on my question. Here is a picture, what i want... http://img41.imageshack.us/img41/592/1fbh.jpg – Sinan Dizdarević Aug 12 '13 at 05:50
  • Instead of a `MouseListener`, use a custom [renderer/editor](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender), for [example](http://stackoverflow.com/a/10067560/230513). – trashgod Aug 12 '13 at 09:44
  • Look, i need when click on edit button, edit row, but i want change action on press enter when editing... Sorry about my english, not the best... :) – Sinan Dizdarević Aug 13 '13 at 01:53

1 Answers1

-1

enter image description here

int key = evt.getKeyCode();

 if (key == KeyEvent.VK_ENTER) {

     //code here

 }

right click to Jtable and event ,KeyReleased.

Shinwar ismail
  • 299
  • 2
  • 9