java 如何向 JTable 单元格添加下拉菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11684903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add a drop down menu to a JTable cell
提问by Sumudu
This may be a question asked before. I searched a lot before posting here, but couldn't figure out any acceptable one.
这可能是之前问过的问题。我在这里发帖之前搜索了很多,但找不到任何可以接受的。
Can some one show me a way how to do this. I simply need to get a drop down menu when i click on the cell so that I'll have to select a value from that (as a way to restrict the user selection).
有人可以告诉我如何做到这一点。我只需要在单击单元格时获得一个下拉菜单,这样我就必须从中选择一个值(作为限制用户选择的一种方式)。
If some one can help with this I believe it will help a lot of people out there. There are a lots of questions similar to this but no any clear answer. Please answer with a bit more details. An example would be much appreciated..
如果有人可以帮助解决这个问题,我相信它会帮助很多人。有很多类似的问题,但没有任何明确的答案。请回答详细一点。一个例子将不胜感激..
Thank you!
谢谢!
回答by mKorbel
use DefaultCellEditor with DefaultTableModel for JTablein the event that all the
JComboBoxes
will have identical values in the concrete TableColumnif will have not identical values, then to use
DefaultCellEditor
forJComboBoxes
with customAbstractTableModel
将DefaultCellEditor 与 DefaultTableModel 用于 JTable,以防
JComboBoxes
在具体 TableColumn中所有这些都具有相同的值如果没有相同的值,则
DefaultCellEditor
用于JComboBoxes
自定义AbstractTableModel