jPopUpMenu 更改鼠标悬停背景
我想在翻转事件时更改 jMenuItems
的背景颜色:
现在它是蓝色的,我想要白色的,我该怎么办? (我使用netbeans GUI)
I would like to change the background color of my jMenuItems
on a rollover event :
Now it's blue, I want it white, how can I do ? (I use netbeans GUI)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用类似以下内容:
问题是这将更改所有菜单项的颜色,甚至是添加到 JMenu 的菜单项。
要控制更改哪些菜单项,您需要创建自定义 MenuItem UI 来替换默认值。然后,您需要修改代码以使用自定义选择背景颜色。
You can use something like:
Problem is this will change the color for all menu items, even those added to a JMenu.
To control which menu items are changed you will need to create a custom MenuItem UI to replace the default. You will then need to modify the code to use your custom selection background color.
我希望能够在应用程序的不同部分使用不同的颜色。我没有使用 UIManager 来更改 LookAndFeel,而是扩展了 javax.swing.plaf.basic.BasicMenuItemUI:-
然后您只需为 JMenuItem 设置 UI:-
I wanted to be able to use different colors in different parts of an app. Rather than use UIManager to change the LookAndFeel, I extended
javax.swing.plaf.basic.BasicMenuItemUI
:-Then you just need to set the UI for your JMenuItem:-