だから私はこれを見てきました: 画面の周りにjlabelをドラッグします
JLabel(またはその表現)をJFrameの外にドラッグする方法はありますか?
たとえば、ドラッグされているJLabelを実際に「表示」しながら、JFrame間でJLabelをドラッグします(http://docs.oracle.com/javase/tutorial/uiswing/dnd/intro.htmlを使用) 。
だから私はこれを見てきました: 画面の周りにjlabelをドラッグします
JLabel(またはその表現)をJFrameの外にドラッグする方法はありますか?
たとえば、ドラッグされているJLabelを実際に「表示」しながら、JFrame間でJLabelをドラッグします(http://docs.oracle.com/javase/tutorial/uiswing/dnd/intro.htmlを使用) 。
JWindowテストの使用:
//http://stackoverflow.com/questions/4893265/dragging-a-jlabel-around-the-screen
private final JWindow window = new JWindow();
@Override
public void mouseDragged(MouseEvent me) {
if (dragLabel == null) {
return;
}
int x = me.getPoint().x - dragLabelWidthDiv2;
int y = me.getPoint().y - dragLabelHeightDiv2;
//dragLabel.setLocation(x, y);
window.add(dragLabel);
window.pack();
Point pt = new Point(x, y);
Component c = (Component)me.getSource();
SwingUtilities.convertPointToScreen(pt, c);
window.setLocation(pt);
window.setVisible(true);
repaint();
}
@Override public void mouseReleased(MouseEvent me) {
window.setVisible(false);
//...
}
以下はテストされていないコードです:(動作するのに多少のマッサージが必要かもしれませんが、これがその要点です)
@Override public int getSourceActions(JComponent src) {
JLabel label = (JLabel)src;
window.add(label);
window.pack();
window.setVisible(true);
return MOVE;
}
//...
DragSource.getDefaultDragSource().addDragSourceMotionListener(new DragSourceMotionListener() {
@Override public void dragMouseMoved(DragSourceDragEvent dsde) {
Point pt = dsde.getLocation();
pt.translate(5, 5); // offset
window.setLocation(pt);
}
});