具有可切换组头的JList [英] JList with toggable group headers
问题描述
是否可以在Java中执行以下图像?
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...
如上图所示,它来自Windows资源管理器,正是我要在Java中使用JList执行的分组列表视图的类型.
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.
推荐答案
在这种情况下,我不认为我会使用JTable
.
I don't think I would use a JTable
in this situation.
首先,我将使用简单的JPanel
和 DesignGridLayout 在 DesignGridLayout摊牌应用程序的"动态布局"部分,例如"示例4-缩进行相同".
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).
然后,我将创建一个从JPanel
派生的DrivePane
,其中将包含驱动器图标作为JLabel
(无文本),将驱动器名称包含为JLabel
,大小包含为JLabel
.我可能会将GridBagLayout
用作DrivePane
的LayoutManager
.该组件将用于显示的每个驱动器.
Then, I would create a DrivePane
deriving from JPanel
, that would contain the drive icon as a JLabel
(with no text), the drive name as a JLabel
, the size as a JProgress
bar, the size as a JLabel
. I would probably use GridBagLayout
as the LayoutManager
for DrivePane
. That component would be used for every drive to show.
这篇关于具有可切换组头的JList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!