1
我想调整位于工具栏中的文本框的大小。我在MainController中创建了一个NewSearchViewController实例类,并且在初始化期间,我添加了一个侦听器,以便在Windows更改Texfield时调整大小。但它不起作用!JavaFX 2.0调整工具栏中的文本框的大小
请帮忙吗?
@FXML
private TextField searchTextField;
public NewSearchViewController() {
FXMLLoader loader = new FXMLLoader();
loader.setController(this);
loader.setRoot(this);
this.setScene(new Scene(this, 600, 450));
try {
loader.load(getClass().getResourceAsStream("/fxml/NewSearchView.fxml"));
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
public void initialize(URL url, ResourceBundle rb) {
searchTextField.setMinWidth(600);
searchTextField.setPrefWidth(600);
this.scene.widthProperty().addListener(
new ChangeListener() {
public void changed(ObservableValue observable,
Object oldValue, Object newValue) {
Double width = (Double) newValue;
searchTextField.setPrefWidth(width);
}
});
}
'stackoverflow.com /问题/ 19919241/gridpane到水平垂直填充最全stage'这可能帮助你 –
好的,我解决了!只需创建一个@FXML私有AnchorPane rootAnchor;并添加将侦听器附加到它。谢谢 – FabSommavilla
这听起来不错....你可以投我的答案 –