Ska
Ska

Reputation: 6888

Java Swing - Copy / Paste doesn't work when in Java Web Start

I created a textfield in Java Swing

txtSessionID = new JTextField();
txtSessionID.setText("enter here");
txtSessionID.setBounds(6, 22, 438, 28);
frame.getContentPane().add(txtSessionID);

When I try to copy something into the textfield it works if I run the jar on desktop but not if I start it with Java Web Start.

The Question:

Why is this so? And How do I make CCP work in the JWS forms?

Upvotes: 2

Views: 1477

Answers (2)

Poulnick
Poulnick

Reputation: 1

This is my answer copy from textfield to another

public class GuiFrame1 {

    private JFrame frame;

    private JTextField textField_1;
    private JTextField textField_2;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    GuiFrame1 window = new GuiFrame1();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public GuiFrame1() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        JLabel NewLabel_1 = new JLabel("\u03A0\u03B1\u03C1\u03B1\u03BA\u03B1\u03BB\u03CE \u03B5\u03B9\u03C3\u03AC\u03B3\u03B5\u03C4\u03B5 \u03C4\u03BF \u03CC\u03BD\u03BF\u03BC\u03AC \u03C3\u03B1\u03C2");
        NewLabel_1.setBounds(10, 11, 191, 14);
        frame.getContentPane().add(NewLabel_1);

        JLabel NewLabel_2 = new JLabel("\u03A4\u03BF \u03CC\u03BD\u03BF\u03BC\u03AC \u03BC\u03BF\u03C5 \u03B5\u03AF\u03BD\u03B1\u03B9");
        NewLabel_2.setBounds(10, 63, 191, 14);
        frame.getContentPane().add(NewLabel_2);

        textField_1 = new JTextField();
        textField_1.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent arg0) {
            //  System.out.println(arg0.getKeyCode());
                if(arg0.getKeyCode()==10) {
                    String name = textField_1.getText();
                    textField_2.setText(name);
                }
            }
        });

        textField_1.setBounds(228, 8, 119, 20);
        frame.getContentPane().add(textField_1);
        textField_1.setColumns(10);

        textField_2 = new JTextField();
        textField_2.setBounds(228, 60, 119, 20);
        frame.getContentPane().add(textField_2);
        textField_2.setColumns(10);
    }
}

Upvotes: 0

Andrew Thompson
Andrew Thompson

Reputation: 168825

The reason for the altered behaviour can be found in Copy in sand-boxed app. in 1.6.0_24+. The security bug fix applies to both applets & JWS apps.

The solution (again outlined in the linked thread) is to use the JNLP API's ClipboardService instead. Here is a demo. of the ClipboardService.

Upvotes: 4

Related Questions