> import java.awt.*;
> import java.awt.event.*;
[quoted text clipped - 23 lines]
>
> //sscce ends
1) You cant run that code as an application. Its an applet.
2) If you dont want to be able to copy at all do this:
ta.setEditable(false);
That makes it impossible to edit the text in the area but you can stille
copy with the mouse.
ta.setEnabled(false);
Make the field not respond to any user action.
> Hi,
>
[quoted text clipped - 52 lines]
>
> Rohit
Looks like bug 6300270 to me.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6300270

Signature
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
...
> I am facing problems when I am trying to copy paste from a JDialog.
'Security'. *
>..Can anyone help me out here?
Possibly.
> I am making an application/applet ..
* ..applets work in a restrictive sandbox that limits
what they can achieve if they are not signed.
An untrusted applet cannot do things like..
- open a connection to a foreign server
- access a variety of user or system properties considered private
- open files on the client's computer
- tap into the user's audio streams
- get information from, or put information on, the clipboard ..
..and that is the problem here. An (unsigned?) applet
is not allowed to access the clipboard.
> Here's an SSCCE which you can try on :
You mention both applications and applets but fail to
provide an SSCCE that can be run as both?!
<admonishing>Tut, tut..</admonishing>
You can confrim what I am saying by runnning *this*
(crudely hacked variant of the earlier) source, as either
an applet or application in your VM of choice.
The application will allow you to copy the text, whereas
the applet will silently ignore you.
<sscce>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DialogApplet
extends JApplet
implements ActionListener {
JDialog d;
public void init() {
JButton b = new JButton("Show Dialog");
b.addActionListener(this);
this.getContentPane().add(b);
}
public void actionPerformed( ActionEvent ie ) {
Frame f = Frame.getFrames()[0];
JTextArea ta = new JTextArea("Are you able to copy this?");
d = new JDialog(f, true);
d.getContentPane().add(ta);
d.pack();
d.setLocationRelativeTo(this);
d.setVisible(true);
}
public static void main(String[] args) {
JFrame f = new JFrame( "Dialog Copy test" );
DialogApplet applet = new DialogApplet();
applet.init();
f.getContentPane().add(applet);
f.pack();
f.setVisible(true);
}
}
</sscce>
The solutions are to either
a) sign your applet so it is again trusted, and thereby
released from the restrictive security sandbox.
b) launch you applet using JWS, which might have a
different behaviour to copying in an unsigned applet.
Note that copy/paste in applets has never been that important
to me that I was bothered to test either approach - they might
work to restore copy/paste behaviour, they might not.
( And as a tip - *always* mention applets in the subject line,
if an applet is involved. Where any problem involves an applet,
there is a >90% chance the problem is *due* to it being an applet. )
HTH
Andrew T.
Rohit Gupta - 27 Jul 2006 15:09 GMT
> * ..applets work in a restrictive sandbox that limits
> what they can achieve if they are not signed.
[quoted text clipped - 8 lines]
> ..and that is the problem here. An (unsigned?) applet
> is not allowed to access the clipboard.
Oh no..so I will have to revert back to frame instead of the JDialog. I
needed the modal property :(.
> > Here's an SSCCE which you can try on :
>
> You mention both applications and applets but fail to
> provide an SSCCE that can be run as both?!
>
> <admonishing>Tut, tut..</admonishing>
My bad...actually I was running as an application in my complete
project, so I had another class which used to launch it. So I forgot to
have the main class in it.
> You can confrim what I am saying by runnning *this*
> (crudely hacked variant of the earlier) source, as either
[quoted text clipped - 54 lines]
> if an applet is involved. Where any problem involves an applet,
> there is a >90% chance the problem is *due* to it being an applet. )
This fact is sinking in me slowly now.... :-)
>HTH
Yeah, it helped. :)
Rohit
Andrew Thompson - 27 Jul 2006 16:40 GMT
...
> Oh no..so I will have to revert back to frame instead of the JDialog. I
> needed the modal property :(.
Huh? You can have a JFrame (application) that pops
a JDialog which can copy/paste, with no problem.
But if you mean to have the unsigned applet pop a
JFrame, you will hit the exact same problem as with
the unsigned applet showing a JDialog.
'Security sand-box - cannot copy'
Andrew T.
Rohit Gupta - 27 Jul 2006 18:30 GMT
> Huh? You can have a JFrame (application) that pops
> a JDialog which can copy/paste, with no problem.
[quoted text clipped - 4 lines]
>
> 'Security sand-box - cannot copy'
I am popping up a JFrame which has a TextArea and I can copy, paste
from it. I don't get the Security problem.
Also in the bug as told by Nigel
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6300270
says that only when you try to use the Modal property you get the
problem. I am getting it able to work using a Frame.
Try this sscce (It's the same one as yours with some further
modification :-) )
//sscce start
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DialogApplet
extends JApplet
implements ActionListener {
JFrame frame;
public void init() {
JButton b = new JButton("Show Frame");
b.addActionListener(this);
this.getContentPane().add(b);
}
public void actionPerformed( ActionEvent ie ) {
JTextArea ta = new JTextArea("Yes, I can copy this for sure!");
frame = new JFrame("Copy frame");
frame.add(ta);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
JFrame f = new JFrame( "Dialog Copy test" );
DialogApplet applet = new DialogApplet();
applet.init();
f.getContentPane().add(applet);
f.pack();
f.setVisible(true);
}
}
//sscce ends
Andrew Thompson - 27 Jul 2006 18:42 GMT
> > Huh? You can have a JFrame (application) that pops
> > a JDialog which can copy/paste, with no problem.
[quoted text clipped - 9 lines]
> Also in the bug as told by Nigel
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6300270
??? Yes. I looked at it. I can see no relevance this this problem.
The source I posted supports that view. I could copy from the
JDialog that was popped out of the frame.
The behaviour you are seeing is no bug.
> says that only when you try to use the Modal property you get the
> problem. I am getting it able to work using a Frame.
I *saw* the copy working for the modal dialog that
was produced out of the application launched from
the command line.
What did you see?
Andrew T.
Rohit Gupta - 27 Jul 2006 18:51 GMT
> ??? Yes. I looked at it. I can see no relevance this this problem.
> The source I posted supports that view. I could copy from the
[quoted text clipped - 12 lines]
>
> Andrew T.
Try the sscce you had posted, and view it using appletviewer. I was not
able to do copy paste from it. However if you run it from the command
line, you are. I hope I am able to clarify the problem.
Rohit
Andrew Thompson - 28 Jul 2006 00:22 GMT
...
> Try the sscce you had posted, and view it using appletviewer.
Sorry Rohit, but sometimes I just have to swear (!#@@*).
OK. I've got that out of my system.
>..I was not
> able to do copy paste from it. However if you run it from the command
> line, you are. I hope I am able to clarify the problem.
You have somewhat missed to point of the example.
It could be run as BOTH an applet* and by calling the main().
The copy behaviour was *different* between the two.
* by running it in only applet viewer, you only saw one
part of what it was written to demonstrate.
When run as an application, I can copy from the frame
dialog without any problems.
Andrew T.
Rohit Gupta - 28 Jul 2006 10:35 GMT
> ...
> > Try the sscce you had posted, and view it using appletviewer.
>
> Sorry Rohit, but sometimes I just have to swear (!#@@*).
>
> OK. I've got that out of my system.
Oops!
> >..I was not
> > able to do copy paste from it. However if you run it from the command
[quoted text clipped - 11 lines]
> When run as an application, I can copy from the frame
> dialog without any problems.
Let me explain you my complete situation.
I have to run my code both as an application as well as an applet.
Initially when I was using the JDialog, I was able to copy/paste from
it in an application but not when I ran it as an applet. This was the
reason for my first post initially. I wanted to do copy paste from
applet. I think you are also saying this.
Now since it was evident I couldn't do a copy/paste from the applet if
I used JDialog, I used a JFrame instead of it as I posted in the last
sscce. This helped me to copy/paste from the *applet* also (apart from
application) which I was desperate for. I hope we are now thinking
along the same lines, or is there still any confusion?
Rohit
Andrew Thompson - 28 Jul 2006 16:53 GMT
....
> Let me explain you my complete situation.
> I have to run my code both as an application as well as an applet.
Thanks. I'd missed that detail and it fills some blanks.
> Initially when I was using the JDialog, I was able to copy/paste from
> it in an application but not when I ran it as an applet. This was the
[quoted text clipped - 3 lines]
> Now since it was evident I couldn't do a copy/paste from the applet if
> I used JDialog,
You *can* if it is signed, and the user trusts it.
(At least I am pretty sure that is the case*)
>...I used a JFrame instead of it as I posted in the last
> sscce. This helped me to copy/paste from the *applet* also (apart from
> application) which I was desperate for. I hope we are now thinking
> along the same lines, or is there still any confusion?
....hmmmm. I think so.
* Either I was wrong all along, or you have
discovered (what appears to be) a security bug.
I believed the Dialog should *not* be able to access the
clipboard when launched from the unsigned Applet - that
has been confirmed by the example I posted.
You explain that a Frame launched from an untrusted
applet *can* access the clipboard.
** It should not be allowed to do so. **
I will need to investigate further, please stay tuned
to this thread for some time to come. It might take
a while and the end result might (possibly) ruin
your current strategy..
Andrew T.
Andrew Thompson - 28 Jul 2006 17:08 GMT
> ....
> > Initially when I was using the JDialog, I was able to copy/paste from
[quoted text clipped - 7 lines]
> You *can* if it is signed, and the user trusts it.
> (At least I am pretty sure that is the case*)
*
> >...I used a JFrame instead of it as I posted in the last
> > sscce. This helped me to copy/paste from the *applet* also (apart from
> > application) which I was desperate for.
Not here it doesn't!
I tried the the source you posted & loaded
the class in the 1.5 JRE applet viewer.
I am *not* able copy text from the frame
(launched by the applet).
* We are back to 'sign the applet'..
Andrew T.
Rohit Gupta - 28 Jul 2006 19:00 GMT
> Not here it doesn't!
>
[quoted text clipped - 4 lines]
>
> * We are back to 'sign the applet'..
I am using JDK 1.5 and I am very much able to copy from the frame which
is being displayed. Infact, not just appletviewer I am able to
copy/paste from it when I run it as an applet on a browser (Mozila
Firefox 1.5 and IE 6). I can't understand why is it not working in your
case.
I'll try in JRE 1.5 and you could well check it on JDK 1.5, if you have
time :)
Rohit
Rohit Gupta - 28 Jul 2006 19:02 GMT
> I'll try in JRE 1.5 and you could well check it on JDK 1.5, if you have
> time :)
Is it one and the same thing in terms of testing?
Rohit
Andrew Thompson - 29 Jul 2006 05:18 GMT
I have taken this up on a thread at c.l.j.programmer..
<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/ac62a
65bcbc0ebe6/71ee71ddd542e90e#71ee71ddd542e90e>
..in the hope of attracting the attention of a small group of
people who can teach me a thing or three about applets.
I suggest you tune into that thread.
Andrew T.
Rohit Gupta - 31 Jul 2006 02:21 GMT
I am currently away from my computer for a few days, returning back to
my country. I have followed the thread which you have mentioned, I need
to try it which I shall do in few days. Will reply as soon as I reach
back.
Thanks for your effort to get the matter cleared up(hopefully) :-)
Rohit
> I have taken this up on a thread at c.l.j.programmer..
> <http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/ac62a
65bcbc0ebe6/71ee71ddd542e90e#71ee71ddd542e90e>
[quoted text clipped - 4 lines]
>
> Andrew T.