CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2000
    Posts
    2

    Help:: Java's getSystemClipboard() does not work in case of an Applet !!!!???? Is that right ??

    I created a class with two text field and two buttons, Copy and Paste. Type some text in the one of the text field and hit Copy I put the text in the clip board by using
    Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
    String strData = textField1.getText();
    stsel = new StringSelection(strData);
    system.setContents(stsel,stsel);

    Hit Paste button and I reads the data from the Clip board and puts it in another text field. Here is the following code:
    try
    {
    String trstring = (String)(system.getContents(null).getTransferData(DataFlavor.stringFlavor));
    TextField2.setText(trstring);
    }

    This works fine if I attach this class from Application and does not work if the same class is attached to a Applet. WHY !!!! am I doing something wrong !!!??
    Can anyone help me, with this stupid thing.



  2. #2
    Guest

    Re: Help:: Java's getSystemClipboard() does not work in case of an Applet !!!!???? Is that right ??

    Just check the browser security settings if Clipboard is enabled there...

    or
    try the following code it works fine for me...

    tt = cp.getContents(JApplet1.this);
    df=tt.getTransferDataFlavors();
    if (tt.isDataFlavorSupported(DataFlavor.stringFlavor))
    {
    try
    {

    if (tt.getTransferData(DataFlavor.stringFlavor)==null)
    str=null;
    else
    str=(String)tt.getTransferData(DataFlavor.stringFlavor);
    }//end try
    catch(UnsupportedFlavorException e_un){str=null;}
    catch(Exception e){str=null; showStatus("Empty Clipboard...");}//end catch



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured