简体   繁体   English

JavaFX标签不会显示

[英]JavaFX labels won't show up

I am trying to practice with BorderPanes, which so far has been a nightmare. 我正在尝试使用BorderPanes进行练习,到目前为止这是一场噩梦。 I have tried to get my label to just show up in the window with no avail. 我试图将标签显示在窗口中而无济于事。 Any ideas? 有任何想法吗?

Label arrayLabel = new Label("NUMBERS");
BorderPane.setAlignment(arrayLabel, Pos.TOP_CENTER);

TextField search = new TextField();
Button btn = new Button("search");
HBox searchbox = new HBox(2);
searchbox.getChildren().addAll(search, btn);
searchbox.setAlignment(Pos.CENTER);

BorderPane root = new BorderPane(arrayLabel);
root.setPrefSize(600, 600);
root.setCenter(searchbox);

A BorderPane can only have one node in any region. BorderPane在任何区域中只能有一个节点。 (That node, of course, could be a parent containing arbitrary numbers of other nodes.) The constructor taking a single parameter treats that parameter as the node to be displayed in the center. (该节点当然可以是包含任意数量其他节点的父节点。) 构造函数采用单个参数会将该参数视为要在中心显示的节点。

So 所以

BorderPane root = new BorderPane(arrayLabel);

is equivalent to 相当于

BorderPane root = new BorderPane();
root.setCenter(arrayLabel);

When you subsequently (immediately) then call 当您随后(立即)拨打电话时

root.setCenter(searchbox);

the center node is replaced by searchbox , so arraylabel is no longer part of the BorderPane . 中心节点被searchbox 替换 ,因此arraylabel不再是BorderPane一部分。

It's not really clear what you intend here: you are essentially trying to put two different UI components ( arrayLabel and searchbox ) into the same region of the same BorderPane . 目前尚不清楚您打算在这里做什么:实际上,您试图将两个不同的UI组件( arrayLabelsearchbox )放入同一BorderPane的同一区域中。 There's no information (provided either to us, or to the poor BorderPane who is trying to position these nodes) as to how you want these two components positioned relative to each other. 没有信息(向我们提供,或者向试图定位这些节点的可怜的BorderPane提供),关于您如何将这两个组件相对放置。 What are you actually trying to achieve, in terms of how you want these laid out? 就您希望这些布局如何,您实际上想实现什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM