简体   繁体   English

使用Nimbus LaF设置JMenuItems边框

[英]Setting JMenuItems border with Nimbus LaF

i am modifying the appearance of some JMenuItems in a popup menu based on some parameters and the currently selected menu item. 我正在基于某些参数和当前选定的菜单项修改弹出菜单中某些JMenuItem的外观。

This is a bit of pseudo code (pseudo, because it doesn't show all the complex process flow, but only the relevant parts of setting the menu items properties ): 这是一些伪代码(伪代码,因为它不显示所有复杂的处理流程,而仅显示设置菜单项属性的相关部分):

JMenuItem item= new JMenuItem("text");
Border border= calculateBorderForItem();
item.setBorder(border);
[...]
item.addMouseListener(new MouseAdapter() {
  public void mouseEntered(MouseEvent e) {
    Color bg= calculateBackgroundForItem();
    item.setBackground(bg);
  }
}

This works quite well with the default Metal LaF, as well as with JGoodies PlasticXP LaF, but not with Nimbus LaF. 这对于默认的Metal LaF以及JGoodies PlasticXP LaF很好,但是对于Nimbus LaF则不行。 Nimbus just ignores all these properties. Nimbus只是忽略所有这些属性。

The background gets painted, when I set item.setOpaque(true) , but still the border doesn't show up. 当我设置item.setOpaque(true) ,背景被绘制,但是边框仍然没有显示。 How can I force Nimbus to use my custom borders? 如何强制Nimbus使用我的自定义边框?

  • Nimbus LaF by default to ignore setBackground , setForeground , etc. Nimbus LaF默认情况下忽略setBackgroundsetForeground等。

  • Nimbus LaF by default never to ignore setBackground , setForeground , in Xxx(Cell)Renderer (not somehow in the connection with your question) 默认情况下, Nimbus LaF永远不会忽略Xxx(Cell)Renderer setBackgroundsetForeground (在某种程度上与您的问题无关)


there are two ways (by override) 有两种方法(通过覆盖)

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

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