如何在工具提示上复制文本

时间:2018-01-24 19:30:42

标签: java javafx

我正在尝试使用工具提示来显示用户和交互的一些文本。如何显示带有文本的工具提示,用户可以复制/粘贴或访问链接。我知道我可以使用setGraphic来添加Text和Link对象,但是如果用户点击其他内容,我怎样才能保持工具提示处于打开状态?

编辑:我正在尝试在TextField的右侧显示PopOver。显示PopOver时,用户应该能够编辑TextField。

我遇到的问题是当显示PopOver时,用户无法对TextField进行任何更改。如果您尝试对显示的TextField进行更改,则不会让您输入任何字符。

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.c

    ontrol.TextField;
    import javafx.scene.layout.Pane;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    import org.controlsfx.control.PopOver;


    public class Test extends Application {

        @Override
        public void start(Stage primaryStage) {


            TextField textField = new TextField("Mouse mouse over me");
            TextArea textArea = new TextArea(textField.getText());
            textArea.setEditable(false);
            PopOver popOver = new PopOver(textArea);

            textField.setOnMouseEntered(mouseEvent -> {
                //Show PopOver when mouse enters label
                popOver.show(textField);
            });

            StackPane root = new StackPane();
            root.getChildren().add(textField);

            Scene scene = new Scene(root, 300, 250);

            primaryStage.setTitle("Hello World!");
            primaryStage.setScene(scene);
            primaryStage.show();
        }

        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            launch(args);
        }
    }

0 个答案:

没有答案