[英]Dragging Jlabel images between two JPanels
To help better understand how we want the program to function here is a list of what we have so far: 为了更好地了解我们希望程序在这里如何运行,列出了到目前为止的内容:
1 JPanel that has a background floor plan image that functions as the “whiteboard” that the user will place objects on. 1个具有背景平面图图像的JPanel,该图像充当用户放置对象的“白板”。
1 JPanel that holds all of the buttons and controls functionality of a selected object in the “whiteboard” panel 1个JPanel,可容纳所有按钮并控制“白板”面板中选定对象的功能
1 JPanel that is placed in a JScrollPanel that holds a list of JLabels with images to be placed on the “whiteboard” panel 1个JPanel放置在一个JScrollPanel中,该JPanel包含一个JLabel列表,其中的图像要放置在“白板”面板上
A class of objects that stores all the properties for each type of furniture item that can be placed; 一类对象,用于存储每种可放置家具类型的所有属性; such as x/y cords, image location, price, labor cost, etc
例如x / y线,图像位置,价格,人工成本等
What we would like to happen is the following: 我们希望发生以下情况:
I don't know if it would be simpler to set up a mouse listener that binds an image to the mouse and then places a copy of it onto the whiteboard wherever it is clicked. 我不知道设置一个将图像绑定到鼠标的鼠标侦听器,然后将其副本放置在白板上,是否更简单。
Here is a link to an image of what has been created so far: http://img824.imageshack.us/img824/4083/o50p.png 这是到目前为止已创建的图像的链接: http : //img824.imageshack.us/img824/4083/o50p.png
Any tips or ideas would be greatly appreciated! 任何提示或想法将不胜感激!
I would have to say use a JToolBar
. 我不得不说使用
JToolBar
。 I say this because it has built-in drag'n'drop. 我说这是因为它具有内置的拖放功能。 If you wanted, you could do this manually using Mouse Listeners and
java2d
. 如果需要,可以使用Mouse Listeners和
java2d
手动执行此操作。 just put the JLabel
images inside a JToolBar
. 只需将
JLabel
图像放入JToolBar
。 good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.