If you encounter this problem, it is most likely that your JTextArea is placed within a JScrollPanel. When the cell editor gets called, the focus is received by the scrolling panel instead of your text area.

To fix this problem, you can add a MouseListener in your JTable and call the editCellAt() method as well as having a getter method in your cell editor class and calling the requestFocusInWindow() method.

That should fix the problem.

Sample code below.

After almost a work day’s worth of searching, I was able to find a solution to my dilemna. While JTextArea has a getLineCount() method to return the number of lines, I wanted a way to also detect wrapped lines since I wanted to set my component a fixed height if the maximum height limit is reached.

This method by user Jörg in the Java forum did the trick.

Converting a mouse position to the caret position of a JTextComponent can be done by using the JTextComponent method viewToModel(). This can be pretty useful if you need to set the caret position of the component when you do a right click of the mouse.

The component can apply to JTextArea, JEditorPane and JTextPane respectively.

Related Posts Plugin for WordPress, Blogger...