How to create an autocomplete popup in JTextPane in Java?

I am creating an SQL editor. I am using JTextPane for the editor. I want to implement AutoCompletion for a table name, etc., for example Eclipse.

+3
source share
5 answers

I think the appropriate class is for displaying information on top of another component JPopupMenuthat already properly processes layering to display itself. JPopupMenu has a method show()that takes its "parent" component as an argument, and it will be displayed in this component coordinate space. Since you want to display a selection of terms for the user, select the appropriate menu.

To check for text changes, you must add DocumentListenerto the document that is wrapped JTextPane; You can access it using getDocument().

, ( , ), getCaretPosition(). int. modelToView() (x, y) . , , , .

addKeyListener(), JTextPane, , Ctrl - Space.

, , .

+5
+3

, , , z-.

, JTextPane, , , , , , .

, .

+2

, JTextPane CTRL + Space. , , , JPopup. , . , , , .

+2

jide. , .

+2

Source: https://habr.com/ru/post/1725866/


All Articles