use*_*928 1 javafx javafx-2 javafx-8
我有一个非常简单的GridPane示例.
GridPane playerGrid = new GridPane();
Text title = new Text("Top Scorers in English Premier League");
title.setFont(Font.font("Arial", FontWeight.BOLD, 20));
playerGrid.add(title, 0,0,4,1);
Run Code Online (Sandbox Code Playgroud)
如何用鼠标选择文本并在程序运行时复制它?
JavaFX中的文本节点不可选.
如果要选择文本,请使用选择感知控件.

例如,使用只读TextField:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class SelectableTextSample extends Application {
@Override public void start(final Stage stage) throws Exception {
stage.setScene(
new Scene(
new SelectableText(
"Top Scorers in English Premier League"
)
)
);
stage.show();
}
class SelectableText extends TextField {
SelectableText(String text) {
super(text);
setEditable(false);
setPrefColumnCount(20);
}
}
public static void main(String[] args) {
Application.launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
替代解决方案
如果您愿意,可以使用WebView.对于某些可能是更好解决方案的情况,但对于其他情况则可能不是.
| 归档时间: |
|
| 查看次数: |
1197 次 |
| 最近记录: |