在JavaFX中,可以通过设置TextArea的editable属性来禁用文本选择。当editable属性设置为false时,用户将无法选择或编辑TextArea中的文本。
以下是禁用文本选择的示例代码:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class DisableTextSelection extends Application {
@Override
public void start(Stage primaryStage) {
TextArea textArea = new TextArea();
textArea.setEditable(false); // 禁用文本选择
VBox root = new VBox(textArea);
Scene scene = new Scene(root, 300, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
在上述代码中,我们创建了一个TextArea并将其editable属性设置为false,这样用户将无法选择或编辑其中的文本。
领取专属 10元无门槛券
手把手带您无忧上云