简体   繁体   English

如何使用Java Swing创建可扩展列表

[英]How to make an expandable list with Java Swing

I need to make an expandable list using java swing. 我需要使用java swing制作一个可扩展的列表。 I will attempt to demonstrate: 我将尝试演示:

Unexpanded: 未展开:

 >[Expand me!]
 >[And me!]

Expanded: 扩展:

 |[Expand me!]
     >[Expand us too!]
     >[Expand us too!]
     >[Expand us too!]
 >[And me!]

So, when you click on the "Expand me" portion of the list, another lists will drop down, possibly containing more expandable lists. 因此,当您单击列表中的“展开我”部分时,另一个列表将下拉,可能包含更多可扩展列表。 If you were to click on it again, it's "sub-lists" would then retract. 如果你再次点击它,那么它的“子列表”将会缩回。 Pretty basic. 很基本的。 And, as you can see, I am not looking for JComboBox, and I do not think JList can do this. 并且,正如您所看到的,我不是在寻找JComboBox,我不认为JList可以做到这一点。 If someone were to point me in the right direction, or give some programming examples, I would be grateful. 如果有人指出我正确的方向,或给出一些编程示例,我将不胜感激。

Thanks, MirroredFate 谢谢,MirroredFate

How about using a JTree . 如何使用JTree

A control that displays a set of hierarchical data as an outline. 一个控件,将一组分层数据显示为大纲。

You can try using a JTable and put a button in the first column. 您可以尝试使用JTable并在第一列中放置一个按钮。 When the button is clicked you add more data in the rows in between. 单击该按钮时,您在其间的行中添加更多数据。

update 更新

Something like this: 像这样的东西:

一棵树

Or this 或这个

用表格

I think the first uses a JTree but that the idea. 我认为第一个使用JTree但是这个想法。

BTW these two belong to JIDE Soft, check if it is feasible for you to buy a license: BTW这两个属于JIDE Soft,检查您是否可以购买许可证:

http://www.jidesoft.com/products/grids.htm http://www.jidesoft.com/products/grids.htm

Is not trivial to roll you own but is not impossible either. 滚动你自己并不是微不足道,但也不是不可能的。

检查TreeTable一个示例大纲 ,但通知,在官方Java(SnOracle)页面上任何进度死亡...,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM