1
當我添加到我的JMenuItem
新圖標或ImageIcon
時,文本變成與圖標相同的顏色。菜單項顯示不正確
我的代碼:
JMenuButton red = new JMenuItem("Red", getIcon(Color.RED));
private Icon getIcon(Color color){
return new Icon() {
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D)g;
g2.translate(x,y);
g2.setPaint(color);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.fillOval(0, 2, 10, 10);
g2.translate(-x,-y);
}
@Override
public int getIconWidth() {
return 14;
}
@Override
public int getIconHeight() {
return 14;
}
};
}