Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I use the paintComponent method with a layout manager

I want to use a layout manager to layout several JButtons, JComboBoxes, etc.. I also want to use the paintComponent method to make a custom background for the JFrame rather than just the normal solid color background. For some reason, the JButtons and other component that have been added to the layout manager show correctly but the shapes that I have drawn in the background with paintComponent do not show up. How can I fix this?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you want to be able to use paintComponent with a layout manager you are not going to be able to do it from withing the class that extends the JFrame. I would recommend adding a JPanel to the JFrame and having the paintComponent method in the JPanel. The JPanel should have no problem using the paintComponent method with the layout manager. If you use setLayout with the JPanel then you should be able to exclude it from the layout manager.

I hope that this answers your question.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading