JList with toggable group headers

戏子无情 提交于 2019-12-11 10:06:45

问题


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.


回答1:


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 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.



来源:https://stackoverflow.com/questions/7394079/jlist-with-toggable-group-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!