如何将 SeparatorField 的宽度限制为固定值?
我有一个 VerticalFieldManager,其中包含两个由 SeparatorField 分隔的普通字段。第二个字段比第一个字段大得多,因此 VFM 向上/向下和向右/向左滚动。
当我不添加 SeparatorField 时,VFM 上的滚动按预期工作 - 我永远无法滚动(垂直或水平)超过第二个字段的内容。
但是,当我添加 SeparatorField (使用默认构造函数)时,它似乎使分隔符无限宽 - 我可以无限向右滚动,远远超出第二个字段的内容,而且我似乎永远不会到达末尾分隔符。
如何根据第二个字段的内容告诉 SeparatorField 仅具有必要的宽度? 我已尝试覆盖 SeparatorField 上的 getPreferredWidth()
,但出现了这种情况没有效果。
I have a VerticalFieldManager that contains two ordinary Fields separated by a SeparatorField. The second Field is much larger than the first, so the VFM scrolls up/down and right/left.
When I don't add the SeparatorField, the scrolling on the VFM works as expected - I am never able to scroll (either vertically or horizontally) past the contents of the second Field.
However, when I add the SeparatorField (with the default constructor), it appears to make the separator infinitely wide - I can scroll infinitely far to the right, well past the contents of the second field, and I never appear to reach the end of the separator.
How can I tell the SeparatorField to only be as wide as necessary according to the contents of the second Field? I have tried overriding getPreferredWidth()
on the SeparatorField, but this appears to have no effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己没有这样做过,但我怀疑重写布局(int,int)应该做到这一点。
像这样的东西:
I haven't done this myself, but I suspect overriding layout(int, int) should do it.
something like:
好吧,我对这个问题的解决方案是完全抛弃
SeparatorField
,并在paint()
方法中在需要的地方画线。Well, my solution to this problem was to throw out the
SeparatorField
entirely, and draw the line where it needs to go in thepaint()
method.