JList 项:更改垂直对齐方式

发布于 2024-08-11 17:40:38 字数 790 浏览 1 评论 0原文

我的应用程序使用 JList 来显示数值。

这是默认显示:

+-----------------+
|value 1          |
|value 2          |
|value 3          |
|                 |
|                 |
|                 |
|                 |
+-----------------+

我想更改垂直对齐方式,以便值显示在框架的右下角,如下所示:

+-----------------+
|                 |
|                 |
|                 |
|                 |
|          value 1|
|          value 2|
|          value 3|
+-----------------+

如果添加新元素,则应显示在底部:

+-----------------+
|                 |
|                 |
|                 |
|          value 1|
|          value 2|
|          value 3|
|          value 4|
+-----------------+

列表是在 JScrollPane 内,限制显示的元素数量。

可行吗?或者我必须使用另一个组件吗?

My application is using a JList to display numerical values.

Here is the default display :

+-----------------+
|value 1          |
|value 2          |
|value 3          |
|                 |
|                 |
|                 |
|                 |
+-----------------+

I would like to change the vertical alignement, so that the values are display at the bottom right of the frame, like this :

+-----------------+
|                 |
|                 |
|                 |
|                 |
|          value 1|
|          value 2|
|          value 3|
+-----------------+

If a new element is added, it should be displayed at the bottom :

+-----------------+
|                 |
|                 |
|                 |
|          value 1|
|          value 2|
|          value 3|
|          value 4|
+-----------------+

The list is inside a JScrollPane, to limit the number of element displayed.

Is it doable ? Or do I have to use another component ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与往事干杯 2024-08-18 17:40:38

作为黑客,也许您可​​以使用 JList 的边框。当列表为空时,您可以调整边框大小以占据列表的所有空间。添加行时,您可以将 Border.top 插图减少行大小。

As a hack maybe you can play with the Border of the JList. When the list is empty you size the Border to take up all the space of the list. When you add a row you decrease the Border.top insets by the row size.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文