aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Drag and drop a textbox. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drag and drop a textbox." Watch "Drag and drop a textbox." New topic
Author

Drag and drop a textbox.

Riddhi Shah
Greenhorn

Joined: Jun 25, 2003
Posts: 19
Is is possible to drag and drop a jtextbox in another application like MS word?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

The text from the textbox or the actual textbox component? Text, yes, definitely... the actual textbox component... maybe... But if so it would take quite a bit of work... you'd have to do some kind of JavaBeans/ActiveX bridge stuff in the drag and drop so that MS Word would recognize the JTextBox. I've never done this myself, but :
  • I'm pretty sure MS Word allows you to drop (or paste) ActiveX components into documents.
  • I know that the JavaBeans API has a JavaBeans/ActiveX bridge so that you can wrap your JavaBean in an ActiveX wrapper so that it can be treated like an ActiveX component by applications that use ActiveX.
  • All Swing components, including JTextArea, are JavaBean components.


  • -Nate
    Write once, run anywhere, because there's nowhere to hide! - /. A.C.
    Riddhi Shah
    Greenhorn

    Joined: Jun 25, 2003
    Posts: 19
    I want to drag a textbox or in that case, any kind of JComponent. I came across this code that drops a label on the word document.
    JLabel label6 = new JLabel(new ImageIcon(im));
    label6.setTransferHandler(new ImageSelection());
    getContentPane().add(label6, BorderLayout.CENTER);
    label6.addMouseListener(mouseListener);
    MouseListener mouseListener = new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (e.getButton() != 3)
    {
    JComponent jc = (JComponent) e.getSource();
    TransferHandler th = jc.getTransferHandler();
    th.exportAsDrag(jc, e, TransferHandler.COPY);
    }
    else
    {
    Point start = e.getPoint();
    copyPopup.show((Component)e.getSource(),start.x,start.y);
    }

    }
    };
    I tried to do the same for Jtextbox and it did not seem to work.
    I will look into JavaBean API and see if I can make that work.
    Thanks.
    Nathan Pruett
    Bartender

    Joined: Oct 18, 2000
    Posts: 4121

    The code you posted just transfers the image on the component... not the actual component itself.
    Riddhi Shah
    Greenhorn

    Joined: Jun 25, 2003
    Posts: 19
    Now I understand what you mean. Till now I was under the confusion that if this code can drag and drop JLabel then why can't it drag and drop a textbox. But I realized that its just the image that is being dragged and not the label.
    I will look in the Java Bean API for more details regarding DnD of Swing Components.
    I will get back with you for more guidance.
    Thanks.
    Riddhi Shah
    Greenhorn

    Joined: Jun 25, 2003
    Posts: 19
    Nathan,
    I downloaded BDK1.1 on my machine. I have never used it before.
    Can you plese help me figure out how to proceed futher so that this will help me drag and drop a textbox on MS Word?
    Need your help.
    Thanks.
    Nathan Pruett
    Bartender

    Joined: Oct 18, 2000
    Posts: 4121

    I don't think you need to get the BDK... all Swing components are JavaBean components already... you just need to somehow make Word think they are ActiveX components when they are dropped in. I searched for "JavaBeans ActiveX bridge" and found this link... which looks like it worked in JDK 1.1 through 1.3.1 and they are updating it in JDK 1.4.2. Though it does mention Word specifically on the page, so it looks like it may be the way to go... I also found this JavaWorld article that gives a tutorial on it.

    Though it looks like there may be a lot of versioning problems with this... the old JavaBeans ActiveX bridge worked in JDK 1.1 - 1.3.1. A new one will work in JDK 1.4.2. And it looks like you have to register each bean as an ActiveX component on each computer you are going to use it on. This might be good for a custom solution to something, but I don't see it as a really good portable solution. (But it's probably the only solution anyway...)
    Riddhi Shah
    Greenhorn

    Joined: Jun 25, 2003
    Posts: 19
    Nathan,
    I really appreciate your help. It has given me some direction to do some more research.
    I also wanted to let you know that we are using JDK1.4.0_03. The article says that the bridge has worked till JDK1.3.1 and will work from JDK1.4.2. I was just curious to know if this would work for JDK 1.4.0_03.
    I will do some more research on this. But as I had also told earlier, I will get back to you for more help.
    Thanks again, I really appreciate your help.
    Nathan Pruett
    Bartender

    Joined: Oct 18, 2000
    Posts: 4121

    I don't know... the JavaBean/ActiveX bridge wasn't included in JDK 1.4.0, but maybe you could get the one from 1.3.1 and see if it worked with 1.4.0 code. I would think that it probably would... as long as you didn't use any classes added after 1.3.1.
    Riddhi Shah
    Greenhorn

    Joined: Jun 25, 2003
    Posts: 19
    Thank you for all your help.
    I am using JDK 1.4.0_03 - for dragging and dropping an image in my application. I think this functionality is not a part of JDK1.3.
    My question is:
    1) How can I incorporate JavaBean Bridge for Active X Contorl in my java code (in my application?).
    2) Is it true that a person who wants to achieve this functionality(drag and drop textbox from application) should have this bridge installed on his machine? I mean is it true that the end-user has to have this bridge installed on his machine inorder to use this application?
    It would be a great help if you could get back with me.
    Looking forward to recieving your reply.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Drag and drop a textbox.