Results 1 to 5 of 5
- 11-08-2011, 11:02 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 2
- Rep Power
- 0
Stop editing jtable cells programatically
Hi people, I'm developing a program that involves a lot of tables, of course I want to save in a file what the user does, so I save the tables as objects in a file.
Problem:
when the cell editor is not working, this is, when the table has no focus at all (and I mean at all because when the Jtables lost the focus, they're still editable, if I write something with the focus on other object, the text appears in the cell I left "open") I can perfectly save the tables as objects in a file.
When I try to save with the cell editor unclosed, I get an exception (therefore the saving is aborted).
I really don't know how to close the f***ing cell editor, and I've triyed everything that people say the use on the forums...
Clear cell editor code (not working) :
My saving code (working with the cell editor closed):Java Code:public void ClearTablesSelection(){ System.out.println("Stopping cell editors"); LocationTable.getSelectionModel().clearSelection(); if (LocationTable.getCellEditor() != null) { LocationTable.getCellEditor().stopCellEditing(); } //the same for the rest of the tables... }
Thanks in advanceJava Code:public void SaveProject(String Filename){ // gather all the objects ClearTablesSelection(); try{ // Catch errors in I/O if necessary. // Open a file to write to, named SavedObjects.sav. FileOutputStream saveFile=new FileOutputStream(Filename); // Create an ObjectOutputStream to put objects into save file. ObjectOutputStream save = new ObjectOutputStream(saveFile); // Now we do the save //EnableTables(false); save.writeObject(lcm.getModel()); save.writeObject(wrm.getModel()); save.writeObject(ws100m.getModel()); save.writeObject(wcm.getModel()); save.writeObject(agm.getModel()); save.writeObject(agp.getModel()); save.writeObject(rwm.getModel()); // Close the file. save.close(); // This also closes saveFile. System.out.println("Project succesfully saved to: " + Filename); } catch(Exception exc){ exc.printStackTrace(); // If there was an error, print the info. } }
- 11-08-2011, 11:47 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: Stop editing jtable cells programatically
- 11-09-2011, 01:00 AM #3
Member
- Join Date
- Nov 2011
- Posts
- 2
- Rep Power
- 0
Re: Stop editing jtable cells programatically
Is this just supposed to work magic?
where is the procedure?
if I create a property it should contain something, am I wrong?
Java Code:JTable table = new JTable(...); table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
this just doesn't work
To anybody reading this, create an empty frame with a JTable and a JButton, the JTable containing a model with some empty cells, run the program, edit one celll and do not press enter, the click the button to quit the focus from th JTable, then write something, and check if youre editing the cell you left open with the focus on the button or not. This is my problem.Java Code:if (table.isEditing()) table.getCellEditor().stopCellEditing();
- 11-09-2011, 02:15 AM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: Stop editing jtable cells programatically
The code from the above link works fine or I wouldn't go to all the trouble of creating the posting.
That is your job. You post the code you wrote to test the problem. Its callled a SSCCE. Short, Self Contained, Correct ExampleTo anybody reading this, create an empty frame with a JTable and a JButton, the JTable containing a model with some empty cells, run the program, edit one celll and do not press enter, the click the button to quit the focus from th JTable, then write something, and check if youre editing the cell you left open with the focus on the button or not. This is my problem.
- 11-09-2011, 02:35 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Similar Threads
-
Add datas to cells of JTable ???
By bilgohan in forum AWT / SwingReplies: 5Last Post: 02-22-2010, 09:56 AM -
Coloring JTable cells
By ProgrammingPup in forum Advanced JavaReplies: 2Last Post: 11-04-2009, 10:57 PM -
How to merge cells of JTable
By nehaa in forum AWT / SwingReplies: 1Last Post: 05-19-2009, 01:07 PM -
how to merge cells /colspan in Jtable
By ravrajesh.ap in forum AWT / SwingReplies: 0Last Post: 01-03-2009, 04:25 PM -
Getting objects from JTable Cells.
By girigl in forum AWT / SwingReplies: 3Last Post: 12-24-2008, 10:46 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks