我有一個對象列表Person (int age, String name)
,存儲在DefaultListModel
中以分配給JList
。顯示來自模型的JList元素
DefaultListModel model;
model = new DefaultListModel();
Person p = new Person(43,"Tom");
//insert in the model
model.add(size, p);
jList1.setModel(model);
我想在JList
只顯示名字,但我無法弄清楚如何做到這一點不使用名稱的另一份名單(我寧願避免)。
是否有任何簡單的方法可以告訴JList
顯示對象Person
的哪些屬性?
閱讀這裏的討論:http://stackoverflow.com/questions/15173325/execute-an-action-when-an -item-on-the-combobox-is-selected-netbeans/15173525 – camickr 2013-03-03 23:36:56