Drawing a JComponent inside a JPanel

梦想与她 提交于 2019-12-06 14:10:23

Maybe a good approach would be that the Icon class would not extend JComponent but would be just a simple object.

Then, you rename the current Icon.paintComponent you have to something like drawIcon and call the drawIcon method from the MyPanel.paintComponent directly and passing the reference to the Graphics object.

This way you don't have to wonder about using a null layout and you can control the place to display the icon to by just using the Graphics(2d) APIs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!