Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swing JTextPane in javafx

Tags:

java

swing

javafx

I'm looking for a rich textarea in javafx. I have tried the RichTextFX component by Tomas Mikula but it is too buggy for my needs.

I was thinking whether it would be possible to plug in a swing JTextPane using the SwingNode class.

So far it actually works as in, I can see the text in the JTextPane and the JScrollPane around it even works. A mouselistener on the JTextPane also seems to be triggered correctly for mouse events but other than that...nothing works.

There is no cursor indicating the current position, no way to "click" with the mouse to change the position, select text,...

Key events simply don't arrive (using a keylistener)

Is it possible to use a JTextPane in javafx and if so, what am I missing?

like image 482
nablex Avatar asked Nov 10 '22 11:11

nablex


1 Answers

Currently I only know a workaround for this problem.
node.setOnMouseReleased(event -> node.requestFocus());
(node is your SwingNode).
I used mouseReleased to mimic the same behavior as the standard FX nodes.

like image 57
user3141592 Avatar answered Nov 15 '22 06:11

user3141592