我遇到的问题的模型:
import javafx.application.Application;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.VBox;
import javafx.scene.control.*;
import javafx.geometry.*;
public class tester extends Application {
@Override
public void start(Stage stage) {
String ipsum = "Lorem ipsum dolor"
+ "\nInteger nec odio."
+ "\nSed nisi. Nulla "
+ "\nPraesent mauris "
+ "\nPraesent mauris"
+ "\nPraesent mauris"
+ "\nPraesent mauris.";
VBox root = new VBox(25);
Label lblHeader = new Label("Place Holder");
TextArea txtOutputBox = new TextArea(ipsum);
Button btnSubmit = new Button("Submit");
VBox.setMargin(txtOutputBox, new Insets(30));
VBox.setMargin(lblHeader, new Insets(10,0,0,10));
txtOutputBox.setFocusTraversable(false);
txtOutputBox.setEditable(false);
txtOutputBox.setFocused(false); // <---- The method setFocused(boolean) from the type Node is not visible
root.setAlignment(Pos.CENTER);
root.getChildren().addAll(lblHeader, txtOutputBox, btnSubmit);
Scene scene = new Scene(root, 350, 250);
stage.setScene(scene);
stage.setTitle("Unexplained");
stage.show();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
launch(args);
}
}
基本上,我正在使用TextArea控件来显示一些旨在只读的文本。为了美观起见,并且为了避免对用户造成干扰,我希望阻止控件获得焦点。我可以轻松地将falseTrueTraversable属性设置为false,但仍然可以通过在控件中单击来赋予控件焦点(尽管无法进行编辑)。
通读文档,TextArea说它从其远亲Node继承了setFocused()方法。当我查看此方法时,文档说它是受保护的。我想过宾果游戏-但是,我对Protected的理解是,它对所有类子类都可用。因此,我不明白为什么子类TextArea无法使用它。
所以,我有两个问题。为了获得优先考虑,第一个对我自己的教育和理解非常有用。我浪费了半天的时间才弄清楚:-(如果有人有一个快速的建议,第二个问题也将很有帮助。
有人可以解释为什么我无法从TextArea子类访问Node的Protected方法(也许不是一个子类,但似乎是)。
关于如何实现此处要完成的工作的任何建议吗?
感谢所有人,