Change Color of MenuBar, Menu, and MenuItem in Java using the AWT Components -


i've been searching around bit, haven't found answer whether or not it's possible , how change background, text, foreground, selection, , text selection colors of menubar, menu, , menuitem awt components.

so-far i've tried following solutions, neither affect of colors of of menu-related components. first solution attempts grab component , change color , second tries change through uimanager.

// example of did, not code i'm working with.     menubar bar = new menubar(); menu menu = new menu(); menuitem item = new menuitem();  bar.getaccessiblecontext().getaccessiblecomponent().setbackground(color.red); bar.getaccessiblecontext().getaccessiblecomponent().setforeground(color.blue);  menu.getaccessiblecontext().getaccessiblecomponent().setbackground(color.red); menu.getaccessiblecontext().getaccessiblecomponent().setforeground(color.blue);  item.getaccessiblecontext().getaccessiblecomponent().setbackground(color.red); item.getaccessiblecontext().getaccessiblecomponent().setforeground(color.blue); 

--

uimanager.put("menuitem.background", color.red); uimanager.put("menuitem.foreground", color.blue); 

i haven't worked awt components before, sorry if answer obvious.


update:

it seems if using awt components bad idea if you're looking able change component colors. i'll refactoring code eliminate many awt components in favour of swing components , suggest reading same if @ possible.

i'd suggest use swing components instead: provide more flexibility:

jmenubar bar = new jmenubar(); bar.setbackground(color.red); bar.setforeground(color.blue); 

you should have no problems integrating swing components existing awt components.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -