Swing and Nimbus: Replace background of JPopupMenu (attached to JMenu)

后端 未结 3 1626
名媛妹妹
名媛妹妹 2021-01-01 20:10

Nimbus often looks great, but for certain color combinations the result is non-optimal. In my case, the background of a JPopupMenu does not fit, which is why I

3条回答
  •  离开以前
    2021-01-01 20:23

    One way to do it is to color the background of the individual JMenuItems and make them opaque:

    JMenuItem a = new JMenuItem("A");
    a.setOpaque(true);
    a.setBackground(Color.GREEN);
    

    Then give the menu itself a green border to fill the rest:

    menu.setBorder(BorderFactory.createLineBorder(Color.GREEN));
    

    There may be an easy/more straightforward way out there, but this worked for me.

提交回复
热议问题