RSyntaxTextArea icon indicating copy to clipboard operation
RSyntaxTextArea copied to clipboard

Autocompletion window (Fx & Swing)

Open AyoubSanhaji opened this issue 6 years ago • 3 comments

When I try to display the autocompletion window it goes back of my FX window, I tried everything but with no result !

Here is what I get.

Thanks in advance

AyoubSanhaji avatar Jul 29 '19 09:07 AyoubSanhaji

I haven't done too much with JavaFX, though I recall it being kind of buggy when I tried to embed Swing components into a JavaFX app (a very long time ago).

Can you provide an SSCCE that demonstrates this behavior?

bobbylight avatar Aug 05 '19 21:08 bobbylight

Here is the SSCCE, all you need is importing the Auto-completion jar file and you ready to go :

public class Main extends Application {
    private RSyntaxTextArea editorZone;
    private JPanel panelSwing = new JPanel(new BorderLayout());

    @Override
    public void start(Stage primaryStage){
        final SwingNode swingNode = new SwingNode();
        SwingUtilities.invokeLater(() -> initSwing(swingNode));
        BorderPane root = new BorderPane();
        root.setCenter(swingNode);
        Scene scene = new Scene(root, 600, 575);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private void initSwing(SwingNode swingNode) {
        swingNode.setContent(panelSwing);
        editorZone = new RSyntaxTextArea(20, 60);
        CompletionProvider provider = createCompletionProvider();
        AutoCompletion ac = new AutoCompletion(provider);
        ac.install(editorZone);
        ac.setShowDescWindow(true);
        ac.setAutoCompleteEnabled(true);
        ac.setAutoActivationEnabled(true);
        ac.setAutoCompleteSingleChoices(false);
        ac.setAutoActivationDelay(0);
        RTextScrollPane editor = new RTextScrollPane(editorZone);
        panelSwing.add(editor);
    }

    private CompletionProvider createCompletionProvider() {
        DefaultCompletionProvider provider = new DefaultCompletionProvider();
        provider.setAutoActivationRules(true, null);
        provider.addCompletion(new ShorthandCompletion(provider, "sysout","System.out.println(", "System.out.println("));
        provider.addCompletion(new ShorthandCompletion(provider, "syserr", "System.err.println(", "System.err.println("));

        return provider;
    }

    public static void main(String[] args) {
        launch(args);
    }
}

AyoubSanhaji avatar Aug 06 '19 06:08 AyoubSanhaji

Hi, I know that this is an old discussion, but do you finally solved the back window problem? I'm still to try place RSyntaxTextArea on JFX form and starting from your code here I don't want have the same problem you had.

Many thanks

maxmeli123 avatar Mar 16 '22 22:03 maxmeli123