The cursor is only painted if the text component has focus.
So if you click on a button, the button will have focus. You can
a) use button.setFocusable(false), then focus will remain on the text component
b) or in the actionPerformed code you add textComponent.requestFocusInWindow();