Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
Name: boT120536 Date: 01/10/2001 >> java -version java version "1.3.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C) Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode) Run the following program. Press the show button to display the modal dialog. Move the modal dialog so it is not directly over the parent frame. Press down on the label in the modal dialog and drag it over the label on the parent frame. Note that the label in the parent frame receives the dragOver and drop events. I would expect a modal dialog to block all events from reaching other windows. --------------------------------------------------------------------- import javax.swing.*; import javax.swing.tree.*; import java.awt.*; import java.awt.dnd.*; import java.awt.datatransfer.*; import java.awt.event.*; public class DnDTest extends JPanel { public static JFrame frame; public class DnDLabel extends JLabel implements DragSourceListener, DropTargetListener, DragGestureListener { protected DragSource dragSource = DragSource.getDefaultDragSource(); protected DropTarget dropTarget = null; public DnDLabel(String label) { super(label); dropTarget = new DropTarget (this, this); dragSource.createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_MOVE, this ); } public void dragDropEnd(DragSourceDropEvent e) { } public void dragEnter(DragSourceDragEvent e) { } public void dragExit(DragSourceEvent e) { } public void dragOver(DragSourceDragEvent e) { } public void dropActionChanged(DragSourceDragEvent e) {} public void dragGestureRecognized(DragGestureEvent e) { System.out.println(getText() + " dragGestureRecognized"); e.startDrag(null, new StringSelection("hello"), this); } public void dragEnter(DropTargetDragEvent dtde) { } public void dragExit(DropTargetEvent dte) { } public void dropActionChanged(DropTargetDragEvent dtde){} public void dragOver(DropTargetDragEvent dtde) { System.out.println(getText() + " dragOver"); } public void drop(DropTargetDropEvent dtde) { System.out.println(getText() + " drop"); } } public DnDTest() { super(new BorderLayout()); JButton button = new JButton("Show"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JDialog dlg = new JDialog(frame, true); dlg.getContentPane().add("Center", new DnDLabel("Modal Label")); dlg.pack(); dlg.setVisible(true); } }); add("Center", new DnDLabel("Main Panel")); add("South", button); } public static void main(String[] args) { frame = new JFrame("DnD Test"); frame.getContentPane().add("Center", new DnDTest()); frame.pack(); frame.setVisible(true); } } (Review ID: 111682) ======================================================================
|