I want JTable column to expand in width if a user enters too many characters into a cell so that content should remain visible. I do not want to use a keylogger as this is not clean, there could be other means of editing a cell.
It seems I can only react in the listeners either at the beginning of an edit or at its end. Can I also react to the editing in between? Or is there maybe something built in? I would have guessed this is a standard task.
I managed to listen to any editing event by using a DocumentListener for each cell.
It indeed works to resize the table during these events - however, if I do so and the column changed in size, the cell I am editing is suddenly colored in blue, as if I have just selected the column with the mouse. The cell however remains in editing mode. I try now to get rid of the blue color by firing some more events. I hope the whole thing does not crash at some point.
Anyway, if I indeed follow this approach, I need to calcuate the required column size based on the characters typed into my cell - a difficult task if I use non-monospaced fonts. Any ideas on that?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.