简体   繁体   English

Java 2D中的拖放小部件

[英]Drag and drop widgets in Java 2D

Is there any material/tutorials available that can shed some light on creating drap and drop widgets with Java 2D? 是否有任何可用的材料/教程可以阐明如何使用Java 2D创建拖放的小部件? I am not talking about drag and drop data transfer like here . 不是这里谈论拖放数据传输。 What I want to do is have a visual pane in my application, where users can create widgets, connect them to each other etc. Something like a creating a graph, but with widgets that have properties. 我想要做的是在应用程序中有一个可视窗格,用户可以在其中创建小部件,将它们彼此连接等。类似于创建图形,但具有具有属性的小部件。

Thanks. 谢谢。

This is generally works like this: 这通常是这样的:

  1. When a user presses the mouse button your application goes to a "drag" mode 当用户按下鼠标按钮时,您的应用程序将进入“拖动”模式
  2. When repaint() method is called while you're in drag mode you move your widget position to the coordinates of the cursor 在拖动模式下调用repaint()方法时,会将小部件位置移动到光标的坐标
  3. When mouse button is released you fixate the ultimate position of the windget. 释放鼠标按钮时,您将固定Windget的最终位置。

The simple illustration for this might be a program I was writing in my youth - interactive chess board. 一个简单的例子可能是我年轻时编写的程序-交互式棋盘。 Here is relevant class that includes pieces dragging capabilities http://jinyan.svn.sourceforge.net/viewvc/jinyan/trunk/jinyan/client/src/net/sfficslecview/lvboard/EditableChessBoard.java?revision=77&view=markup 这是相关的类,其中包括片段拖动功能http://jinyan.svn.sourceforge.net/viewvc/jinyan/trunk/jinyan/client/src/net/sfficslecview/lvboard/EditableChessBoard.java?revision=77&view=markup

I have found the perfect solution. 我找到了完美的解决方案。 I can make use of the Netbeans Visual Library by extracting jar from the Netbeans Platform. 我可以通过从Netbeans平台提取jar来利用Netbeans可视库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM