How do I prevent underlying dividers from poking through my menu!
I've got a Swing form made up of a JFrame containing a JMenuBar and a JSplitPane (further subdivided into resizeable JPanels). The problem is that when I select one of the drop down menus, if one of the dividers for the JPanels is under the menu, it actually gets rendered on TOP of the menu! As if the divider had focus instead of the menu.
I had this same problem with another (similar project tha开发者_运维技巧t I did), never found a fix, just gave up using a menubar (went to a tab/keystroke based system). I really want to make menus work on this current project, hopefully without having dividers poking through the menus and annoying me. :-)
Ideas?
Make sure you're using lighweight Swing components and not heavyweight AWT components. (ie: JPanel instad of Panel, JMenuBar instead of MenuBar, etc.)
Combining heavyweight and lightweight components often results in the problems you're seeing.
OK, I got it, and it's an interesting case indeed!
I eventually figured out that some of the code in part of the form is injecting some custom components. Delving into those custom components reveals that they're painting into the graphics space (via fill3DRect)... Items painted that way always end up displayed/"on top"...
Now, to try to figure out how to make them function in a Swing world... :-)
精彩评论