Replicate JMenu in paintComponent of child

82 views Asked by At

Where would I find the code or how would I create the code to replicate a JMenu in the paintComponent Method using a custom class that extends JMenu?

I have looked through the jdk and cannot find the code for drawing a JMenu in its own class or any of it parents.

I just need the text and icon placement code.

1

There are 1 answers

0
Jason Braucht On

Painting of lightweight Swing components is delegated to the pluggable look-and-feel implementation. This is why you aren't seeing any painting code in JMenu.

In the case of JMenu the class responsible for painting would be a child of javax.swing.plaf.MenuItemUI. Exactly which depends on what L&F you are using. For example, the Windows L&F would delegate painting of the menu to com.sun.java.swing.plaf.windows.WindowsMenuUI

Probably the easiest way to achieve your goal is to look at the implementation for the particular L&F you want to extend, then override the paintComponent() method to perform your custom painting.

Take a look at "Performing Custom Painting" for a decent explaination on how to paint custom components.