如何在javafx textarea中获取智能感知

时间:2020-09-18 07:36:39

标签: javafx textarea intellisense

我需要一个帮助以获取智能(在文本区域上键入一个单词时,它将建议几个单词自动选择),用于以下代码。正在从“ suggestionList”数组中获取建议。

-MyTest.fxml文件的代码--------

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.BorderPane?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.161" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MyTest">
   <center>
      <TextArea fx:id="txtTextArea" onKeyReleased="#txtChangeEvent" prefHeight="400.0" prefWidth="600.0" BorderPane.alignment="CENTER" />
   </center>
</BorderPane>

-MyTest.java控制器的代码---

package application;

import javafx.fxml.FXML;
import javafx.scene.control.TextArea;

public class MyTest {
    
    String[] suggestionList = new String[] {"apple", "orange", "doll","dog","plane","plate","place"};
    
    @FXML
    TextArea txtTextArea = new TextArea();

    public void txtChangeEvent() {
        String fullText = txtTextArea.getText();
        System.out.println("full text is >>> " + fullText);
    }
}

-Main.java类的代码----

package application;
    
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("MyTest.fxml"));
            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}

0 个答案:

没有答案