Java swing, scrollbar does not working with absolute layout

我的未来我决定 提交于 2019-11-28 14:40:23

I cant use any layout manager because i need to create an rectangle/circle at a location where user clicks (and allow drag & drop for all the created emelents)

Well, you can't use a standard layout manager from the JDK, but yes you SHOULD be using a layout manager because a layout manager does more than just set the location of a component.

Scrollbar will never pop up.

Your scrolling doesn't work because the panel doesn't have a proper preferred size based on the components added to the panel.

Check out the Drag Layout which is a layout manager designed for this purpose. It allows random placement but it still calculates a preferred size so scrolling will work.

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