-
Enhancement
-
Resolution: Unresolved
-
P5
-
None
-
6u3
-
x86
-
windows_xp
The Actions that returns from getActionMap() should be use universal on buttons and menus. This is not correct for some actions from JTextPane. for example InsertHR. The problem is that the target JTextPane is searching from the event source:
public void actionPerformed(ActionEvent ae) {
JEditorPane editor = getEditor(ae);
The event source is the button or the menu. This means that this actions can only work with KeyEvents from the JTextPane / JEditorPane self. This is bad. The only workaround is to replace the Sune classes with a own implementation.
Test Program
============
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.text.Document;
public class InsertHR {
public static void main( String[] args ){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
final JTextPane text = new JTextPane();
Action action = text.getActionMap().get("InsertHR");
JButton insert = new JButton();
frame.add( insert, BorderLayout.NORTH );
insert.setAction(action);
insert.setText( "Insert HR" );
frame.add( text );
String anyText = "<html>" +
"<head></head><body>" +
"any text" +
"</body></html>";
text.setContentType( "text/html" );
Document doc = text.getDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
text.setText( anyText );
frame.setSize( 300, 200 );
frame.show();
}
}
public void actionPerformed(ActionEvent ae) {
JEditorPane editor = getEditor(ae);
The event source is the button or the menu. This means that this actions can only work with KeyEvents from the JTextPane / JEditorPane self. This is bad. The only workaround is to replace the Sune classes with a own implementation.
Test Program
============
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.text.Document;
public class InsertHR {
public static void main( String[] args ){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
final JTextPane text = new JTextPane();
Action action = text.getActionMap().get("InsertHR");
JButton insert = new JButton();
frame.add( insert, BorderLayout.NORTH );
insert.setAction(action);
insert.setText( "Insert HR" );
frame.add( text );
String anyText = "<html>" +
"<head></head><body>" +
"any text" +
"</body></html>";
text.setContentType( "text/html" );
Document doc = text.getDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
text.setText( anyText );
frame.setSize( 300, 200 );
frame.show();
}
}