JTable help needed

Is there a way to get programmatic control of the actual text editor that is used by JTable when you are modifying text within the table? I want to be able to change the default behavior of the editor but so far I can't find a way to even access it. I've been playing around with the DefaultCellEditor class but this seems to only relate to the starting and stopping of editing, not to the object that is actually allowing you to type and do the editing of the text.

I've been searching all over the net and can't seem to find anything related to this. I can't be the first person to want to do this. Please help!

[631 byte] By [PingGuya] at [2007-11-27 11:51:40]
# 1

If what you want is to have control of the editor, your best bet would probably be to register your own editor. You can set a default editor by class type via the JTable.setDefaultEditor(Class,TableCellEditor) or add it directly to the TableColumn if it's for a particular column.

jarza at 2007-7-29 18:39:39 > top of Java-index,Desktop,Core GUI APIs...
# 2

> I want to be able to change the default behavior of the editor

Not a very descriptive requirement so we can't give you much help other than to point you to the JTable API where you click on the link to the Swing tutorial on "How to Use Tables" which shows you how to write a custom editor:

camickra at 2007-7-29 18:39:39 > top of Java-index,Desktop,Core GUI APIs...
# 3

I'm not sure if I'm logged in with the same ID I used to post this yesterday, but this is the same person responding.

I'll try to be as descriptive as I can this time:

When you edit text in a JTable you are editing it inside of a JTextField as far as I understand it. I want to be able to access that JTextField programmatically and have it behave a certain way when certain events happen. I've read the JTable article mentioned above and I didn't see anything in there on how to do this. Please let me know if this makes more sense.

Thanks.

ApparantlyNota at 2007-7-29 18:39:39 > top of Java-index,Desktop,Core GUI APIs...
# 4

You can get the editor using the getDefaultEditor(...) method. Then you cast the editor to a DefaultCellEditor and you can use the getComponent(...) method to return the text field.

Of course if you told us what you mean by "... and have it behave a certain way...", then maybe we could provide a better solution.

That is what a requirement is. You tell us "what" you want to do, not "how" you are currently doing it. Then we can confirm if your current approach is valid, or suggest an alternative approach.

camickra at 2007-7-29 18:39:40 > top of Java-index,Desktop,Core GUI APIs...
# 5

Thanks, I'll give that a shot. I think I was missing the casting part and then the grabbing of the component.

To be honest I'm not sure exactly what I want to do with it yet. For starters I want to perform a selectAll() on the JTextField when editing begins so that any text that is typed replaces the contents. Beyond that I'm sure there will be other things, I just haven't figured out what they are yet.

ApparantlyNota at 2007-7-29 18:39:40 > top of Java-index,Desktop,Core GUI APIs...
# 6

> For starters I want to perform a selectAll() on the JTextField when editing begins

Then state that as the requirement and search the forums. If you find an answer to that question, it may give you ideas for your future requirements.

Try something like this:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=640471

camickra at 2007-7-29 18:39:40 > top of Java-index,Desktop,Core GUI APIs...