Hi Duncan-

I can't quite get your modifications to make Steve's app work, but
that's not important.  It's not really difficult to paste _inside_ a
Java application.  I think what Steve Zara was doing was highlighting
text in some (say,) non-Java application, and thus then pasting that to
the Java app from the system clipboard.  In that case one receives the
"X11Selection" error I discussed in my previous post, which I discovered
debugging a problem with a CoreJava example.

Say I highlight a couple of words in your e-mail and then use the paste
button in Steve's java application (with your mods), then I get:
-----
Exception occurred during event dispatching:
java.lang.NullPointerException: 
        at
sun.awt.motif.X11Selection.isDataFlavorSupported(X11Selection.java:223)
        at clipboard$2.actionPerformed(clipboard.java:53)
        at java.awt.Button.processActionEvent(Button.java:257)
        at java.awt.Button.processEvent(Button.java:230)
        at java.awt.Component.dispatchEventImpl(Component.java:1781)
        at java.awt.Component.dispatchEvent(Component.java:1708)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:81)
----
i.e., more or less what Steve was getting.

Whereas, if one makes the change to (gutting of!) his button method as I
mentioned:
-----
...
        b2.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {

              Transferable data=Clip.getContents(this);
              //System.out.println("data is: "+data);
                String result = "";
                try {
                    result =
(String)data.getTransferData(DataFlavor.stringFlavor);
                }
                catch (Exception ex) {;}
                t2.setText (result);
                t1.setText (result);
            }
        });
...
-------
a paste of some non-Java stuff works (shows up in both areas.)

Matters are a bit confused here, IMO because there's not a lot of
agreement on what's being attempted. ;-)

FWIW.

Bob L.
-- 
Robert Lynch-Berkeley CA [EMAIL PROTECTED]
http://www.best.com/~rmlynch/
================
Duncan Roe wrote:
> 
> The application now works for me after changing 2 lines. At least, after Copy of
> slected text in pane 1 and "Paste", both panes display the text and nothing else
> - was that the intention?
> 
> Using jdb, I found that the mime-type of the message was "text/plain;
> charset=unicode", which Transfer's getTransferData method didn't recognise,
> therefore returning null.
> 
> The second problem was that once getTransferData returned a non-null object, the
> cast of it to StringReader caused a runtime exception. A cast to String is OK
> however.
> 
> The changes are appended. Why it worked as-is on the other platforms is another
> question.
> 
> -Duncan
[major snip of Steve Zara's code, to which was appended the error msg:]
> > The stack trace is:
> > Exception occurred during event dispatching:
> > java.lang.NullPointerException:
> >         at sun.awt.motif.X11Selection.isDataFlavorSupported(X11Selection.java:223)
> >         at clipboard$2.actionPerformed(Main.java:53)
> >         at java.awt.Button.processActionEvent(Button.java:254)
> >         at java.awt.Button.processEvent(Button.java:227)
> >         at java.awt.Component.dispatchEventImpl(Component.java:1764)
> >         at java.awt.Component.dispatchEvent(Component.java:1704)
> >         at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)
> >
[snip]
> 
>     ---------------------------------------------------------------
> 
>                               Name: t5
>              Part 1.2         Type: Plain Text (text/plain)
>                        Description: Context diff of changes

Reply via email to