简体   繁体   English

如何创建JList和灰色按钮当用户从列表中选择项目时,按钮颜色变为黑色?

[英]How to create JList and Gray Button When user select item from the list the button color change to black?

Iam trying to make normal JList and when the user select item the button change, i guess if there is any action listener or something i could add? 我试图制作正常的JList,当用户选择项目按钮改变时,我想是否有任何动作监听器或我可以添加的东西? i don't actually know 我其实不知道

I guess you could use a ListSelectionListener . 我想你可以使用ListSelectionListener It will generate an event every time the selection changes. 每次选择更改时,它都会生成一个事件。

Read the section from the Swing tutorial on How to Write a ListSelectionListener for more information and working examples. 阅读Swing教程中有关如何编写ListSelectionListener的部分, 获取更多信息和工作示例。

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

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