Jtable disable hover selected row - java

i have a little problem with jtable :
when i click on the Appliquer utton, he clera all the table except the in-write cell, so i need to unset in-write mode??
that how it look like when i have clicked Appliquer button :

You are still editing the data in the cell so it has not bee saved to the TableModel yet.
See Table Stop Editing for a couple of solutions that will make sure the data is saved when you click a button.

Try to use:
table.clearSelection();
Or for a particular cell use.
columnModel.getSelectionModel().clearSelection();

Related

Editing JList in a JTable

I have a JTable whose every cell contains a JList. What I want to do is to make that table editable so that every item on the JList can be edited either using a JTextfield or Choosing an item from another List whenever the user right clicks on that list item in a particular table cell. I also want 2 of my table column need to be set uneditable. Here is a picture of my JTable. I want the every cell and every JList item on that cell to be editable leaving the 'Batch' and 'Break' column to be uneditable.
P.S. I don't want any spoon fed code. I just want an idea how it can be done. And I'll be really grateful if you can reference me some link on the web where I can read to learn how this type of problems can be solved. Thank you..!
enter image description here

Jtable losing multiple row selection,when button in one of the column is clicked

I have a very basic problem with jtable. I have a jtable that has multiple columns with one of column having a button. When i click on that button a panel drops, and asks to select an option from given options. When i select that option, value replaces in one of the column.
Now, i want when i select multiple rows, and do the same thing as above, it should replace that column in all the selected rows.
Problem: Currently, my table is losing selection when i am clicking the button in one of the column in jtable after multiple row selection.
I searched google and stackoverflow a lot, but could not find anything meaningful. Anyhelp or sample code is appreciated.
Thanks
If I understood your problem correctly then the solution is fairly simple.
First of all the issue probably occurs because once you click on the button java sets a new focus on the button and therefore clearing the focus on the other rows. That won´t be a problem in a single selection because you still click into the selected row, however doing that with multiple rows in one go won´t work that way.
To solve this you need to save your previous selections in something like an ArrayList and after the whole option thing you can apply the changes to every element in the ArrayList and reload the table.
A cleaner and more intuitive approach though would be to place the button outside of the JTable.

Cell editor not exiting when row is deleted

I have a JTable with a several columns, one of which is has a custom renderer to display 3 buttons in a JPanel as well as a custom editor to allow them to be clickable. One of the buttons sends a delete command to our server for that row id then reloads the table data from the server by clearing the data model and loading data again. When this happens the cell with the 3 buttons continues to display (but not the rest of the row) until I click another button in another row even though the row is gone.
I've set putClientProperty("terminateEditOnFocusLost", Boolean.TRUE) but changing focus to another component does not help.
I've tried deleting the row itself before refreshing the data (even deleted all the rows) and made sure to call fireTableRowsDeleted().
I've also tried calling the cancelCellEditing() and stopCellEditing() functions of the TableCellEditor and even manually setting the editing row/column to another cell.
Any help would be greatly appreciated.
Ok, so I figured it out. I ended up calling removeEditor() on the table and that fixed it.
Thanks for the responses.
I've set putClientProperty("terminateEditOnFocusLost", Boolean.TRUE) but changing focus to another component does not help.
That method should be invoked when you create the table, not in the actionPerformed method when you click the button.
Ok, so I figured it out. I ended up calling removeEditor() on the table just before the data refresh and that fixed it.
Thanks for the responses.

how to force cell editor in jtable to accept edits

i have a jtable with multiple editable cells
when someone presses the "save button" on the menu, it doesn't save the last value that is still currently being edited. (unless they tab out of the cell first)
i can check it is being edited by calling .isEditing() which returns true.
What i would prefer to do is trigger that the cell editing is complete, and it can show any validation errors, and if none, then save. (without the user having to tab out first)
can someone please point me in the right direction
thanks
You can manually call:
JTable table;
table.getCellEditor().stopCellEditing();
This should cause the table to stop editing at that cell. By overriding the stopCellEditing() method of your TableCellEditor and returning false under certain circumstances, you can indicate that the cell's value is currently invalid and thus editing cannot be stopped at that time.
when you have a jtable with multiple editable cells
when someone presses the "save button" on the menu, it doesn't save the last value then please add the below peace of code
The first is to have the table automatically stop editing and save the data. This can be done by setting a property on the table:
JTable table = new JTable(...);
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
It will make sure that when someone presses the any button on the menu, it saves the last edited value also.
If I remember correctly, edited/added value is present in cell editor component by default it is EditBox, BUT do not present in table model. If it is possible try to check cell editor component it should help you.

How to handle JTable data changed event

I have a JTable bound to a List property. I used NetBeans to add a property to my jpanel form, enabled/checked propertyChangeSupport, and bound my jTable to that property. Table is displaying the data perfectly. Please guide me how can I enable/disable a 'Save' button when data of this table is changed by double-clicking a cell and editing its contents.
The Table Cell Listener will listen for real changes in the data of a cell.
A TableModelListener fires an event even if you tab out of the cell and don't actually change the data.
Have you tried adding a TableModelListener to the JTable's model? This should fire any time the table's data is changed, and the listener can then enable your save button. The button should disable itself whenever it is pressed and the data has been successfully saved.
Edit:
Please ignore this and instead go with camickr's recommendation!

Categories

Resources