简体   繁体   English

如何绑定到这个 JList 以便我可以更改向用户显示的内容?

[英]How do I bind to this JList so I can change what gets displayed to the user?

I have a JList which i want to use to display a list a caches that are added in from another form, I've got this working and I want to be able to add the caches directly to the list... Is there a way to change what gets displayed to the user?我有一个 JList ,我想用它来显示一个从另一个表单添加的缓存列表,我已经完成了这项工作,我希望能够将缓存直接添加到列表中......有没有办法更改向用户显示的内容? or would it simply be a case of making to the toString method of my object what i want to be displayed?还是只是对我的 object 的 toString 方法制作我想要显示的内容?

public void update(Observable o, Object arg)
{
    GeoGolfHole hole = (GeoGolfHole)arg;
    model.add(0, hole);
    jlHolesInGame.setText(Integer.toString(model.getSize()));
}

You can create a new ListCellRenderer to render what you want out of the class.您可以创建一个新的 ListCellRenderer 以从 class 中呈现您想要的内容。

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

相关问题 如何在JPanel内部使用JList,以便可以设置列表的边界? - How do I use JList inside of JPanel So I can set the bounds of the list? 如何让JList项目显示在JTextField中 - How can I get JList item to be displayed in a JTextField 如何修改此程序以包含八个 colors 的 JList,可用于更改此小程序的背景颜色? - How do I modify this program to include a JList of eight colors that can be used the change the background color of this applet? 如何刷新 JList? - How do I refresh a JList? 如何更改Java Swing中显示的内容? - How do I change what's being displayed in Java Swing? 如何使用户可以选择我的JList? - How can I make my JList selectable by the user? 我该如何更改JList d'n'd目标指标 - How can I change JList d'n'd target indicator 如何更改未选择的JList项目的背景颜色? - How can i change the background color of a JList item that is not selected? 如何设置我的图形,以便用户可以更改大小并保持比例? - How do I setup my Graphics so that a user can change the size and stay in proportion? 如何更改服务器上项目的顺序,客户端将显示正确的顺序? - How can I change the order of the items on the server and the client gets the correct order to be displayed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM