-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.3.0
-
x86, sparc
-
linux, solaris_7
Name: boT120536 Date: 01/12/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
This is similiar to Bug Id 4227934 except with the mouse.
The hacked up example included below reproduces the effect.
The point is that a TextField allows one to paste in text
that has been previously selected with the left mouse button
(from other non-java applications)
with a press of the middle mouse button. The standard linux utility
"gpm" is the utility that handles this copy/paste action.
Many unix utilities/editors readily accept such mouse copy/paste
actions...I pasted the below code from an editor directly into
this "bug" report window with this feature.
A TextField handles this kind of paste fine.
A JTextField ignores it.
Comment out the line:
final TextField textfield = new TextField(40);
and uncomment the line:
//final JTextField textfield = new JTextField(40);
To see the effect.
My apologies if this is not due to a bug but rather to my
ignorance using JTextField vs TextField.
Thank You,
Jim
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
public class Copy implements DocumentListener{
// set up frames, panels, text areas
JFrame frame = new JFrame("Clipboard demo");
JPanel panel = new JPanel();
// Use TextField to see "proper" paste action with
// linux gpm mouse daemon
final TextField textfield = new TextField(40);
// Use JTextField to see nothing with linux
// gpm mouse daemon.
//final JTextField textfield = new JTextField(40);
// create buttons and set up listeners for them
JPanel buttonpanel = new JPanel();
JButton copybutton = new JButton("Copy");
JButton pastebutton = new JButton("Paste");
JButton exitbutton = new JButton("Exit");
Copy() {
panel.setLayout(new BorderLayout());
// If a JTextField ... shows the insertUpdate etc. messages
//textfield.getDocument().addDocumentListener(this);
// The following from Bug Id: 4227934 doesn't help.
/*
textfield.loadKeymap(JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP),
new JTextComponent.KeyBinding[] {
new JTextComponent.KeyBinding
(KeyStroke.getKeyStroke(KeyEvent.VK_COPY, 0),
DefaultEditorKit.copyAction),
new JTextComponent.KeyBinding
(KeyStroke.getKeyStroke(KeyEvent.VK_PASTE, 0),
DefaultEditorKit.pasteAction) },
new DefaultEditorKit().getActions());
*/
copybutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Clipboard cb =
Toolkit.getDefaultToolkit().
getSystemClipboard();
String s = textfield.getText();
StringSelection contents =
new StringSelection(s);
cb.setContents(contents, null);
textfield.setText("");
}
});
pastebutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Clipboard cb =
Toolkit.getDefaultToolkit().
getSystemClipboard();
Transferable content =
cb.getContents(this);
try {
String s =
(String)content.
getTransferData(DataFlavor.
stringFlavor);
textfield.setText(s);
}
catch (Throwable exc) {
System.err.println(e);
}
}
});
exitbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
buttonpanel.add(copybutton);
buttonpanel.add(pastebutton);
buttonpanel.add(exitbutton);
panel.add("North", textfield);
panel.add("South", buttonpanel);
// make frame visible
frame.getContentPane().add("Center", panel);
frame.pack();
frame.setVisible(true);
}
public static void main(String args[]) {
new Copy();
}
public void insertUpdate(DocumentEvent e) {
System.out.println("\ninsertUpdate");
}
public void removeUpdate(DocumentEvent e) {
System.out.println("\nremoveUpdate");
}
public void changedUpdate(DocumentEvent e) {
System.out.println("\nchangedUpdate");
}
}
(Review ID: 114856)
======================================================================
- duplicates
-
JDK-4407942 SELECTION in Swing-based apps. does not "interact" with Motif2.x applications
-
- Closed
-
-
JDK-4197227 Allow cut/copy from Swing text comp to be pasted into std X win (via MMB, etc.)
-
- Resolved
-