现在有一个界面是拖曳的的面板,想把资源管理器的模式对话框嵌入到面板的上面,用户直接就可以拖曳了,
不知道该怎么做,会做的请告诉一声

解决方案 »

  1.   

    楼主是想用swing做jfilechooser文件选择对话框?还是做拖动面板的功能啊?
      

  2.   

    File f1=new File("c:\\");
    JFileChooser jfc=new JFileChooser(f1);
    jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    jfc.showDialog(null,"确定");
    int result = jfc.showOpenDialog(this);
    if (result==jfc.APPROVE_OPTION){
                  File file=jfc.getSelectedFile();
               }
      

  3.   

    我是想如何做一个像jfilechooser弹出的对话框的那种窗口把在面板的上面,不是弹出式的,然后直接可以从里面把文件拖出来放到下面的面板里
      

  4.   

    这个用swing做?恐怕有点困难哦,呵呵
    看看有没有高手帮你了
      

  5.   


    /**
    * @version 1.00 1999-09-11
    * @author Cay Horstmann
    */import java.awt.*;
    import java.awt.datatransfer.*;
    import java.awt.event.*;
    import java.awt.dnd.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;public class DropTargetTest

    public static void main(String[] args)
    { JFrame frame = new DropTargetFrame();
    frame.show();
    }
    }class DropTargetFrame extends JFrame
    { public DropTargetFrame()
    { setTitle("DropTarget");
    setSize(300, 300);
    addWindowListener(new WindowAdapter()
    { public void windowClosing(WindowEvent e)
    { System.exit(0);
    }
    } );Container contentPane = getContentPane();
    JTextArea textArea
    = new JTextArea("Drop items into this text area.\n");new DropTarget(textArea,
    new TextDropTargetListener(textArea));
    contentPane.add(new JScrollPane(textArea), "Center");
    }
    }
    class TextDropTargetListener implements DropTargetListener
    { public TextDropTargetListener(JTextArea ta)
    { textArea = ta;
    }public void dragEnter(DropTargetDragEvent event)
    { int a = event.getDropAction();
    if ((a & DnDConstants.ACTION_COPY) != 0)
    textArea.append("ACTION_COPY\n");
    if ((a & DnDConstants.ACTION_MOVE) != 0)
    textArea.append("ACTION_MOVE\n");
    if ((a & DnDConstants.ACTION_LINK) != 0)
    textArea.append("ACTION_LINK\n");if (!isDragAcceptable(event))
    { event.rejectDrag();
    return;
    }
    }public void dragExit(DropTargetEvent event)
    {
    }public void dragOver(DropTargetDragEvent event)
    { // you can provide visual feedback here
    }public void dropActionChanged(DropTargetDragEvent event)
    { if (!isDragAcceptable(event))
    { event.rejectDrag();
    return;
    }
    }public void drop(DropTargetDropEvent event)
    { if (!isDropAcceptable(event))
    { event.rejectDrop();
    return;
    }event.acceptDrop(DnDConstants.ACTION_COPY);Transferable transferable = event.getTransferable();DataFlavor[] flavors
    = transferable.getTransferDataFlavors();
    for (int i = 0; i < flavors.length; i++)
    { DataFlavor d = flavors[i];
    textArea.append("MIME type=" + d.getMimeType() + "\n");try
    { if (d.equals(DataFlavor.javaFileListFlavor))
    { java.util.List fileList = (java.util.List)
    transferable.getTransferData(d);
    Iterator iterator = fileList.iterator();
    while (iterator.hasNext())
    { File f = (File)iterator.next();
    textArea.append(f + "\n");
    }
    }
    else if (d.equals(DataFlavor.stringFlavor))
    { String s = (String)
    transferable.getTransferData(d);
    textArea.append(s + "\n");
    }
    else if (d.isMimeTypeEqual("text/plain"))
    { String charset = d.getParameter("charset");
    InputStream in = (InputStream)
    transferable.getTransferData(d);boolean more = true;
    int ch;
    if (charset.equals("ascii"))
    { do
    { ch = in.read();
    if (ch != 0 && ch != -1)
    textArea.append("" + (char)ch);
    else more = false;
    } while (more);
    }
    else if (charset.equals("unicode"))
    { boolean littleEndian = true;
    // if no byte ordering , we assume
    // Windows is the culprit
    do
    { ch = in.read();
    int ch2 = in.read();
    if (ch != -1 && littleEndian)
    ch = (ch & 0xFF) | ((ch2 & 0xFF) << 8);
    if (ch == 0xFFFE)
    littleEndian = false;
    else if (ch != 0 && ch != -1)
    textArea.append("" + (char)ch);
    else more = false;
    } while (more);
    }textArea.append("\n");
    }
    }
    catch(Exception e)
    { textArea.append("Error: " + e + "\n");
    }
    }
    event.dropComplete(true);
    }public boolean isDragAcceptable(DropTargetDragEvent event)
    { // usually, you check the available data flavors here
    // in this program, we accept all flavors
    return (event.getDropAction()
    & DnDConstants.ACTION_COPY_OR_MOVE) != 0;
    }public boolean isDropAcceptable(DropTargetDropEvent event)
    { // usually, you check the available data flavors here
    // in this program, we accept all flavors
    return (event.getDropAction()
    & DnDConstants.ACTION_COPY_OR_MOVE) != 0;
    }private JTextArea textArea;
    }
      

  6.   

    上面是拖拽的实现
    至于你想怎么嵌入没看明白,百度关键字
    swing 拖拽
    java DropTargetListener
    http://www.cnblogs.com/hemry/archive/2008/09/11/1289530.html
      

  7.   

    不知你是不是要类似Windows的资源管理器哦,我倒是有一个.
      

  8.   

    7楼的是用swt做的吗,好像原生的,不错。
      

  9.   

    7楼的能不能给我发一份哪个资源管理器的源码,[email protected]
      

  10.   

    谢谢请给我发一份 [email protected]