Name: yyT116575 Date: 10/06/2000
Please note that I have no idea what version of HotSpot I have, and I just
picked 1.0.1 arbitrarily. How do you check the HotSpot version?
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
This bug involves HotSpot producing a stack overflow, when the VM should
produce a StackOverflowError.
#
# HotSpot Virtual Machine Error, EXCEPTION_STACK_OVERFLOW
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Error ID: 4F533F57494E13120E43505002D4
#
The cause is very clearly the code from processComponentKeyEvent() since it
calls super.processKeyEvent, which calls processKeyEvent, etc. I was
experimenting with solving the JPopupMenu not receiving key events bug (4107667/
Here is the code to the program. Just run it and try to type in the text field.
package com.qindesign.ui;
import java.awt.datatransfer.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.KeyEvent;
import javax.swing.*;
import javax.swing.text.Document;
/**
* JTextField that implements a Cut/Copy/Paste popup.
*
* @author Shawn Silverman
*/
public class EditPopupTextField extends JTextField {
public static void main(String[] args) {
JFrame f = new JFrame("EditPopupTextField");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel();
p.add(new EditPopupTextField(20));
f.getContentPane().add(p);
f.pack();
f.show();
}
private JPopupMenu popup;
// Create a new class so actionPerformed can be extended properly
private final ActionListener menuListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if ("Cut".equals(cmd)) {
EditPopupTextField.this.cut();
} else if ("Copy".equals(cmd)) {
EditPopupTextField.this.copy();
} else if ("Paste".equals(cmd)) {
EditPopupTextField.this.paste();
}
}
};
public EditPopupTextField() {
super();
init();
}
public EditPopupTextField(Document doc, String text, int columns) {
super(doc, text, columns);
init();
}
public EditPopupTextField(int columns) {
super(columns);
init();
}
public EditPopupTextField(String text) {
super(text);
init();
}
public EditPopupTextField(String text, int columns) {
super(text, columns);
init();
}
protected void processComponentKeyEvent(KeyEvent e) {
//System.err.println("field: " + e);
if (popup.isVisible()) {
popup.dispatchEvent(e);
e.consume();
} else {
super.processKeyEvent(e);
}
}
private void init() {
JMenuItem menuItem;
// Create the popup menu
popup = new JPopupMenu() {
protected void processComponentKeyEvent(KeyEvent e) {
System.err.println("popup: " + e);
}
};
menuItem = new JMenuItem("Cut", KeyEvent.VK_T);
//menuItem.setAccelerator(KeyStroke.getKeyStroke(
// KeyEvent.VK_X, ActionEvent.CTRL_MASK));
menuItem.addActionListener(menuListener);
popup.add(menuItem);
menuItem = new JMenuItem("Copy", KeyEvent.VK_C);
menuItem.addActionListener(menuListener);
popup.add(menuItem);
menuItem = new JMenuItem("Paste", KeyEvent.VK_P);
menuItem.addActionListener(menuListener);
popup.add(menuItem);
// Add listener to this
this.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
maybeShowPopup(e);
}
public void mouseReleased(MouseEvent e) {
maybeShowPopup(e);
}
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});
}
/**
* Only pastes the first line of the text in the clipboard.
*/
public void paste() {
// Manual paste to remove newlines
Clipboard clipboard = getToolkit().getSystemClipboard();
Transferable content = clipboard.getContents(this);
if (content != null) {
try {
String dstData = (String)(content.getTransferData
(DataFlavor.stringFlavor));
replaceSelection(firstLine(dstData));
} catch (Exception ex) {
getToolkit().beep();
}
}
}
// Only paste the first line.
private String firstLine(String s) {
int nlIndex = s.indexOf('\n');
int crIndex = s.indexOf('\r');
if (nlIndex >= 0) {
if (crIndex >= 0) {
nlIndex = Math.min(nlIndex, crIndex);
}
return s.substring(0, nlIndex);
} else if (crIndex >= 0) {
return s.substring(0, crIndex);
}
return s;
}
}
(Review ID: 109566)
======================================================================
- duplicates
-
JDK-4298656 stack yellow zone not re-enabled after a StackOverflowError
-
- Closed
-