Reputation: 2563
i am modifying the appearance of some JMenuItems in a popup menu based on some parameters and the currently selected menu item.
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. Nimbus just ignores all these properties.
The background gets painted, when I set item.setOpaque(true)
, but still the border doesn't show up. How can I force Nimbus to use my custom borders?
Upvotes: 1
Views: 175
Reputation: 109823
Nimbus LaF
by default to ignore setBackground
, setForeground
, etc.
Nimbus LaF
by default never to ignore setBackground
, setForeground
, in Xxx(Cell)Renderer
(not somehow in the connection with your question)
there are two ways (by override)
JMenuItem
s paintComponent()
, paintBorder()
, paintChildren
all proper Keys in Nimbus Defaults,
Upvotes: 2