S-JIS[2007-02-25] 変更履歴
ひしだま作のマウスでのドラッグ用ウィンドウです。→ソース
クラス | 説明 |
---|---|
DragWindow | ドラッグ用に、擬似的に背景を透過した四角(枠線)を表示するウィンドウ。 ウィンドウ作成時に全画面を保存し、移動したら保存してある移動先の画像を表示している。 つまり、ドラッグ中には画面の他の部分が動かないだろうという暗黙の期待がある(苦笑) 例えば時計の表示が変わったり、割込みによって新しくウィンドウが開いたりすると、途端に化けの皮がはがれる(爆) しかも全画面を保存しているので、強力なマシンでないと実行にちょっとした時間がかかる(嘆) |
DragBoxWindow | ドラッグ用に、四角い枠(背景は透過しない)を表示するウィンドウ。 |
DragImageWindow | ドラッグ用に、画像を表示するウィンドウ。 |
JLabel label = new JLabel("ドラッグするラベル"); MouseHandler mh = new MouseHandler(); label.addMouseListener(mh); label.addMouseMotionListener(mh);
class MouseHandler extends MouseAdapter implements MouseMotionListener { protected DragWindow win; protected JComponent drag; public void mousePressed(MouseEvent e) { drag = (JComponent) e.getSource(); win = new DragWindow(親ウィンドウ, e.getPoint(), drag.getLocationOnScreen(), drag.getSize()); win.setVisible(true); } public void mouseReleased(MouseEvent e) { if (win != null) { Point pt = win.getLocation(); SwingUtilities.convertPointFromScreen(pt, drag.getParent()); drag.setLocation(pt); drag = null; win.setVisible(false); win.dispose(); win = null; } } public void mouseDragged(MouseEvent e) { win.setMouseLocation(e.getPoint()); } public void mouseMoved(MouseEvent e) { } }