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

后端 未结 3 1627
名媛妹妹
名媛妹妹 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:30

    not the whole story - but looks like setting the opacity of menu/items to true partly solves it (as @Derek Richard already did for a item created under full application control):

    UIDefaults ui = UIManager.getLookAndFeelDefaults();
    ui.put("PopupMenu.background", GREEN);
    ui.put("Menu.background", GREEN);
    ui.put("Menu.opaque", true);
    ui.put("MenuItem.background", GREEN);
    ui.put("MenuItem.opaque", true);
    

    and so on, for all types of items like radioButton/checkBox.

    This still leaves a upper/lower grey area - don't know which part is responsible for that drawing. Removing the margin helps at the price of looking squeezed

    // this looks not so good, but without the margins above/below are still grey
    ui.put("PopupMenu.contentMargins", null);
    

    There's a list of property keys in the tutorial.

提交回复
热议问题