Is it possible to have “movable”/“draggable” components like JButtons, JTextFields in a JFrame?

妖精的绣舞 提交于 2019-12-05 09:14:26

The Component Mover can do this for you.

Use the GlassPane: http://download.oracle.com/javase/tutorial/uiswing/components/rootpane.html

It's an invisible panel that sits on top of all other components. You can attach mouse listeners to it and then use SwingUtilities.getDeepestComponentAt() to figure out which component was clicked on beneath the GlassPane. Then use a mouseDragged listener on the glasspane and set the component location based on the mouse dragged event.

You will need to set the layout of your container to "null" so the components' setLocation will work.

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