Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6623968

Some Actions from JTextPane.getActionMap() does not work with Buttons

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P5 P5
    • None
    • 6u3
    • client-libs

      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();
          }
      }

            peterz Peter Zhelezniakov
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: