miglayout 行格式:包含 1 行 JTextArea 的 JScrollPane
如果需要,我想显示一个带有水平滚动条的单行文本标签。 (没有垂直滚动条,因为我知道它是一行。)
我通过包含 JTextArea 的 JScrollPane 实现。
对于布局管理器,我正在使用 MigLayout,但似乎无法弄清楚行格式规范的用途。如果我只使用 []
那么它在没有水平滚动条的情况下工作得很好,但是当滚动条出现时,它看起来很糟糕,因为滚动条占据了所有空间。
我想做的是:
- 显示具有恒定高度的 JScrollPane,当滚动条存在时看起来不错,并且当滚动条不存在时有额外的空间
- 显示具有可变高度的 JScrollPane,以便窗格的高度为 1当滚动条不存在时的文本行,或者当滚动条存在时用于容纳滚动条的附加空间
- 以仅需要 1 行文本的方式显示 JScrollPane(例如,滚动条被更改,以便它占用一些水平空间有关文本的右侧)
有什么建议吗?
I want to display a one-line text label that has a horizontal scrollbar if necessary. (No vertical scrollbar since I know it's one line.)
I am implementing via a JScrollPane containing a JTextArea.
For layout manager, I am using MigLayout and can't seem to figure out what to use for the row format specification. If I just use []
then it works fine for no horizontal scrollbar, but when the scrollbar appears, it looks bad since the scrollbar takes up all the space.
What I would like to do is either:
- show the JScrollPane with a constant height that looks good when the scrollbar is present, and has extra space when the scrollbar is absent
- show the JScrollPane with variable height so that the height of the pane is the 1 line of text when the scrollbar is absent, or an additional space to accomodate the scrollbar when it's present
- show the JScrollPane in a way that only takes 1 row of text (e.g. the scrollbar is changed so that it eats up some of the horizontal space to the right of the text in question)
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有趣的问题(我并没有像我应该的那样过度热衷于研究 jpa )
基本上,布局本身不能做太多事情:scrollPane 的首选大小根据水平滚动条的可见性而不同。在我看来,客户端代码可以动态地告诉管理器如何处理要覆盖的区域。下面是一个可以使用的代码片段。
对于 Win/Nimbus 工作得很好,但 Metal 中有一个小故障(也许还有其他 LAF),需要对差异进行神奇的数字调整以保持布局稳定
非常欢迎反馈,也许有一种我忽略的不那么人为的方法
Interesting problem (and me not overly enthused with looking into jpa as I should )
Basically, it's not much a layout could do on its own: the pref size of the scrollPane differs depending on the visibility of the horizontal scrollBar. It's up to client code to dynamically tell the manager what to do with the to-be covered area, IMO. Below is a code-snippet to play with.
Works fine for Win/Nimbus, there's a glitch in Metal, though (and maybe other LAFs) which needs a magic number adjust of the diff to keep the layout steady
Feedback highly welcome, maybe there is a less artificial approach that I overlooked