2016-12-14 8 views
1

У меня есть TextArea и TextField в моем приложении. Мне удалось сфокусироваться на TextField с самого начала и сделать TextArea невозможным для редактирования. Я также хочу как-то отключить возможность сфокусировать его с помощью простого щелчка мыши или циклического табуляции.JavaFX - Отключение возможности фокусировки на TextArea

Есть ли подходящий способ для этого?

+1

Отключение узел должен сделать это. – Mordechai

ответ

1

Вы должны использовать:

textArea.setFocusTraversable(false); 
textArea.setMouseTransparent(true); 

Пример демонстрации:

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.TextArea; 
import javafx.scene.layout.BorderPane; 
import javafx.stage.Stage; 

/** 
* @author StackOverFlow 
* 
*/ 
public class Sample2 extends Application { 

    @Override 
    public void start(Stage primaryStage) throws Exception { 
     BorderPane pane = new BorderPane(); 

     // Label 
     TextArea textArea1 = new TextArea("I am the focus owner"); 
     textArea1.setPrefSize(100, 50); 

     // Area 
     TextArea textArea2 = new TextArea("Can't be focused "); 
     textArea2.setFocusTraversable(false); 
     textArea2.setMouseTransparent(true); 
     textArea2.setEditable(false); 

     // Add the items 
     pane.setLeft(textArea1); 
     pane.setRight(textArea2); 

     // Scene 
     Scene scene = new Scene(pane, 200, 200); 
     primaryStage.setScene(scene); 

     // Show stage 
     primaryStage.show(); 

    } 

    /** 
    * Application Main Method 
    * 
    * @param args 
    */ 
    public static void main(String[] args) { 
     launch(args); 
    }