Sayuri Coppinger

Greenhorn
+ Follow
since Jun 06, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sayuri Coppinger

Have you tried creating a table cell renderer and table cell editor which returns an editor pane or text pane that uses the rtf editor kit? These two text components provide the getEditorKit and the setEditorKit methods. Thus, when set, the editor pane would effectively transform itself into an editor for the rtf text format.
PS. Let us know if this works
Sayuri
20 years ago
Yeah, I thought the same thing but no such luck. BTW, if your table is contained in a scrollpane, you might run into some problems traversing the table with the tab key. You will need to tab twice and sometimes even 3 times! This is a known bug. I actually ended up taking my table out of the scrollpane to get the behaviour I wanted.
Just some things to keep in mind....Like I said I did struggle to get it working
20 years ago
If you want the cell to expand only when editing, you could use your own table cell editor (more or less the same concept as the cell renderer)
But if you want the cell to always have the same "look", then you will need to change the row height of the table, and make the appropriate changes in your renderer to always have the same preferred size...
Sayuri

Originally posted by illya figotin:
Sayuri:
Yes, I check for isSelected. But the end, any changes I've made will disappear, because JTable puts my JTextArea in the cell area, so it is still in the cell rectangle, and it doesn't look like JTextArea.
Could you please advise me something in this case?
Thanks.
Ilya.


20 years ago
Use the changeSelection method, and make sure you have the cell selection enabled as well
[This message has been edited by Sayuri Coppinger (edited August 13, 2001).]
20 years ago
I had the same problem, and I resolved by calling the setAutoCreateColumnsFromModel(false). The default is to always create the columns from the model. So whenever the model changes, the columns get resized...
20 years ago
I am not sure I follow your question completely, but to select a single cell, you need to call the setCellSelectionEnabled() method on the table, and to move the selection to a different cell, you can use the changeSelection(...) method
[This message has been edited by Sayuri Coppinger (edited August 11, 2001).]
20 years ago
One of the parameters in the get table cell renderer component is the flag isSelected. You can check for this flag, and if it is selected you can change the way the component looks. That is you can change its size, font, background and so on...
20 years ago
I came across the same problem and struggled with it for a couple of days, but finally got it figured out.
You need to implement isCellEditable(row,col) in your data model to return the appropriate boolean flag for the cells. Then add a key listener to the table and implement the keyReleased method to check for VK_TAB key code, if it is the tab key, then loop through your table, checking to see if the cell is editable. If editable, call changeSelection method to change to the next editable cell.
The logic is actually a bit more involved than this, but this should get you started. The other thing I would do is add a focus listener to clear selection on focus lost and change selection to the first editable cell on focus gained. Also, if you are planning to tab out of the table using the tab key as opposed to CTRL TAB, then you need to use the focus manager when you are tabbing out of the last editable cell.
Good luck!
Sayuri
20 years ago
Just wanted to update anyone having the same problems I mentioned above, that what I had forgotten to do was to call fireTableCellUpdated method when setting the value.
As for the tabbing issue, I had to use a combination of focus listener, key listener and focus manager to get the focus to go to only editable cells and if the user was on the last cell to go to next focusable component. It sounds simple, but it was a struggle to get it right since my editable cell could be anywhere within the table.
Thanks to all who participated in this thread
20 years ago
Hi,
After I make a change to the cell, I simply click on a button. I've added the code you wrote above to my action performed and it still doesn't update the model. I am using jdk 1.3
Also, I have another question for you. Some of my cells are readonly, and when I tab through the cells, I want to skip the readonly cells. I was thinking I could check if the cells is editable and just get the next focusable (or editable cell). Is there a quick way of doing this, or do I have to implement the key listener and look for the tab and shift tab keys?
Thanks for your help and interest !

Originally posted by Swamy Vatti:
Hi,
Can you give me some more info, the sequence of events...
Like after editing the cell, what do you do?
I had the same problem and now its working perfect.
Can you tell me what JDK version are you using?


20 years ago
Thank you all for replying. I added the code below, but it didn't work. The values only get set if I select another cell. I am running out of ideas....

Originally posted by Swamy Vatti:
Hi,
If you are doing some action, lets say button click, after updating the table, put this code in the action performed method.
int row = yourTable.getEditingRow();
int col = yourTable.getEditingColumn();
if (row != -1 && col != -1)
yourTable.getCellEditor(row,col).stopCellEditing();
I guess this should work perfect.


20 years ago
When I make changes to a cell, I can see that the value has changed in the table, but I can't retrieve the value until the selection (not focus)is no longer at that cell, but at another cell. I can change the focus to a different component, but as
long as the cell selection remains, the value does not get set in my underlying data object.
I've tried clearing the cell selection, setting the setCellSelection back to false, firing a table model event with the cell that gets updated, implementing the list selection listener and nothing seems to be working
Does anybody know why I have to select another cell before the value gets set, and how I can get around this?
Any ideas would be very much appreciated!
Thanks,
Sayuri
20 years ago
Swamy,
Thanks a lot, you've made my day! I knew it was something obvious, just couldn't put my finger on it. Thanks again for your input. It would be my luck that for the cells that I was testing which was using the custom textfields, the value was not being set. I just validated Murphy's Law
Sayuri

Originally posted by Swamy Vatti:
Then I guess the renderer is not picking up the value from the model.
In the getTableCellRendererComponent(Object value,....)
set the components text to the 'value' from the parameter.
ie TextField.setText(value.toString());


20 years ago
I have implemented the setValueAt in the table model, and I know it is setting the value, because when I enter the cell and type something, the value that was set and what I typed shows up.
The problem is that the value only shows up when you enter the cell and change it. As soon as you leave the cell, the value is no longer displayed.
Thank you all for replying, it is helping me eliminate all the possible things that could have gone wrong

Originally posted by Swamy Vatti:
Hi,
This is because u dont have the implementation for the method setValueAt of TableModel.
Implement this method and I guess you should not be having any problems


20 years ago
Paul,
Thanks for replying. I am not following what you mean by "supply code to renderer".
My renderer subclasses from DefaultCellRenderer and overrides the getTableCellRendererComponent(..) method which is currently returning the correct component. It also has a method to return the editor for the given component.
What other code is there to supply? Could you please be more specific?
Thank you,
Sayuri
20 years ago