【发布时间】:2015-03-18 15:28:28
【问题描述】:
在上面,我添加了一个屏幕截图 - 现在我可以添加图像了。屏幕截图的底部显示了场景的边缘(外部容器 2 上没有滚动条)。
这个场景可能变得太忙了——但我正在尝试使用包含 FlowPane 或 VBox 的嵌套滚动窗格。我正在定义“内部容器”,它是一个 VBox,包括一个文本字段和滚动窗格,其中包含一个流窗格作为其内容。流程窗格加载了许多“状态块”。内部容器的滚动窗格似乎工作正常。下面是来自内部容器的代码 sn-p:
public class InnerContainer extends VBox
{
// Declare the various parts of the inner container
private TextField m_icName = null; // Name of the inner container
private ScrollPane m_icScroll = null;
private FlowPane m_icFlow = null; // Holds the status blocks
// List of status blocks in this inner container
private ArrayList<StatusBlock> m_statBlockList = null;
/******************************************************************
* Create the containers and controls used by the inner container *
******************************************************************/
public InnerContainer()
{
m_statBlockList = new ArrayList<>(); // Set up list of status blocks
setMinSize(200.0, 170.0);
setPrefSize(200, 170);
setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
setPadding(new Insets(5, 5, 5, 5));
m_icName = new TextField();
m_icName.setMaxWidth(Double.MAX_VALUE);
m_icScroll = new ScrollPane();
m_icScroll.setFitToWidth(true);
m_icScroll.setFitToHeight(true);
m_icScroll.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
VBox.setVgrow(m_icScroll, Priority.ALWAYS);
m_icFlow = new FlowPane();
m_icFlow.setPrefWrapLength(650.0); // This is the "wrap" point
m_icFlow.setVgap(5);
m_icFlow.setHgap(5);
m_icFlow.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
m_icScroll.setContent(m_icFlow);
// Add the elements to the vbox
getChildren().addAll(m_icName, m_icScroll);
VBox.setVgrow(this, Priority.ALWAYS);
我无法让滚动条在外部容器中正常工作。如果我添加内部容器,外部容器只会不断增长,我永远无法显示滚动条(即使它超过了屏幕的大小)。我怀疑我无法正确计算外部容器内容的大小。外部容器是一个 VBox,其中包含一个文本字段和一个具有 VBox 内容的滚动窗格。最终的 VBox 可以由一对多的内部容器组成。
这是来自外部容器的代码 sn-p:
public class OuterContainer extends VBox
{
// Declare the various parts of the outer container
private TextField m_ocName = null; // Name of the outer container
private ScrollPane m_ocScroll = null;
private VBox m_ocMainVBox = null;
private ArrayList<InnerContainer> m_innerContList = null;
public OuterContainer()
{
// Setup the inner container list
m_innerContList = new ArrayList<>();
setSpacing(8);
setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
setPadding(new Insets(5, 5, 5, 5));
m_ocName = new TextField();
m_ocName.setMaxWidth(Double.MAX_VALUE);
m_ocScroll = new ScrollPane();
m_ocScroll.setFitToWidth(true);
m_ocScroll.setFitToHeight(true);
m_ocScroll.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
VBox.setVgrow(m_ocScroll, Priority.ALWAYS);
m_ocMainVBox = new VBox();
m_ocMainVBox.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
VBox.setVgrow(m_ocMainVBox, Priority.ALWAYS);
m_ocMainVBox.setSpacing(5);
m_ocMainVBox.setMinSize(1.0, 1.0);
m_ocScroll.setContent(m_ocMainVBox);
// Add the elements to the top vbox
getChildren().addAll(m_ocName, m_ocScroll);
VBox.setVgrow(this, Priority.ALWAYS);
有一个最终的外部类也应该有一个滚动条。它也不能正常工作,但我怀疑这个问题与我在这里寻求帮助的问题相似。
提前感谢您的帮助。
【问题讨论】:
-
如果外部容器应该有一个滚动条,为什么你扩展一个
VBox而不是ScrollPane? -
它扩展 VBox 而不是 ScrollPane 的原因是外部容器包含一个文本字段(用于命名容器)和滚动窗格。
-
一个VBox里面有多个TextField和ScrollPane组合吗?当你说,“我永远无法显示滚动条(即使它超出了屏幕的大小)”,你想在 VBox 上显示滚动条吗?
-
外部容器包含一个 TextField 和一个 ScrollPane。 ScrollPane 的内容是一个 VBox(可以容纳许多内部容器)。正如您所提到的,我永远无法显示滚动窗格的滚动条 - 无论包含的 VBox 有多大。我一直在努力找出原因。我的怀疑是我需要使用具有 height 属性的 bind() 方法,但我无法弄清楚它应该绑定到什么。
-
现在可以发图片了吗?