具有可切换组标题的 JList
在Java中是否可以做类似下图这样的事情?
我知道我需要使用带有自定义单元格渲染器的多列列表,以便显示每个列表元素的图像。但我的问题是关于对列表元素进行分组,并使用组标题...
正如您从上图中看到的,它来自 Windows 资源管理器,并且正是我希望使用 Java 中的 JList 实现的分组列表视图类型
Is it possible to do something like the following image in Java?
I understand that I would need to be using a multi columned list, with a custom cell renderer, in order to show the images of each list element. But my question is regards to Grouping the list elements, and using group headers...
As you can see from the image above this comes from windows explorer and is exactly the type of grouped list view that I would be looking to do with a JList in Java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在这种情况下我不会使用
JTable
。首先,我将使用一个简单的
JPanel
和 DesignGridLayout,类似于DesignGridLayout Showdown 应用程序中演示的示例,“动态布局”部分,示例“示例 4 - 与缩进行相同”。在该示例中,您必须更改用于轮廓效果的图标(示例中为三角形而不是 V 形)。
然后,我将创建一个派生自
JPanel
的DrivePane
,其中包含作为JLabel
的驱动器图标(无文本)、驱动器名称作为JLabel
,大小作为JProgress
条,大小作为JLabel
。我可能会使用 GridBagLayout 作为 DrivePane 的 LayoutManager。该组件将用于每个要显示的驱动器。I don't think I would use a
JTable
in this situation.First of all, I'd use a simple
JPanel
with DesignGridLayout, something like the example demonstrated in DesignGridLayout showdown application, section "Dynamic Layouts", example "Example 4 - Same with indented rows".In that example you'd have to change the icons used for the outline effect (triangles instead of chevrons in the example).
Then, I would create a
DrivePane
deriving fromJPanel
, that would contain the drive icon as aJLabel
(with no text), the drive name as aJLabel
, the size as aJProgress
bar, the size as aJLabel
. I would probably useGridBagLayout
as theLayoutManager
forDrivePane
. That component would be used for every drive to show.