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

JTextComponent.paste() doesn't honor isEditable() and isEnabled()as cut() does

XMLWordPrintable

    • beta
    • generic, x86
    • generic, windows_95, windows_nt



      Name: vi73552 Date: 04/19/99


      JTextComponent.paste() does not honor whether it is editable
      or enabled:

      public void paste() {
        Clipboard clipboard = getToolkit().getSystemClipboard();
        [..]

      In contrast, cut() does it right (IMHO):

      public void cut() {
        if (isEditable() && isEnabled()) {
        [..]

      This is allows pasting in TextFields, which are marked as
      non-editable to avoid any changes to it. This is a one-liner
      to fix.
      (Review ID: 57142)
      ======================================================================

      Name: vi73552 Date: 06/22/99


      Paste is allowed on NON-editable JTextComponents
      when the hotkey isused: ie. on Windows ctrl-v to paste will
      actually paste text into a non-editable field !!!!

      The below test case will allow you to paste into the
      top text field (non-editable). Fill the clipboard and
      then select the non-editable text field. Even though
      no cursor is displayed you can continue to paste into
      it.

      import javax.swing.*;

      public class Test extends JPanel
      {
              public Test()
              {
                      setLayout( new BorderLayout());

                      JTextField field1 = new JTextField("uneditable", 40);
                      field1.setEditable(false);

                      JTextField field2 = new JTextField("editable", 40);

                      add( field1, BorderLayout.NORTH);
                      add( field2, BorderLayout.SOUTH);
              }
              public static void main( String[] args )
              {
                      JFrame frame = new JFrame();
                      frame.getContentPane().add( new Test());
                      frame.pack();
                      frame.show();
              }
      }
      (Review ID: 84078)
      ======================================================================

      Name: krT82822 Date: 11/16/99


      java version "1.1.8"


      Defined a JTextArea. Set setEditable value to false. After compile using
      JDK 1.1.7, displayed the window on a JDK 1.1.8 client. Put the cursor in the
      text area. Selected some of the text with the mouse, then copied (via CTRL-C) to
      paste buffer. With the cursor still in the text area, pasted from paste buffer
      (via CTRL-V). The text in the paste buffer was placed into the text area that
      should have been uneditable. The value isn't saved, but is redisplayed if the
      window is reopened without being refreshed.

      The above is also true of a JTextField.

      The bug did not occur if the client ran with JDK 1.1.7, which is why the
      subcategory Swing was not selected.

      SOURCE CODE:

      import java.awt.*;
      import javax.swing.*;

      public class PasteBug extends javax.swing.JFrame {

         public PasteBug () {
            Container win = getContentPane ();
            this.setSize (450, 200);
            this.setTitle ("Paste Bug Example");
            win.setLayout (new GridBagLayout ());

            GridBagConstraints c1 = new GridBagConstraints ();

            c1.fill = GridBagConstraints.BOTH;
            c1.anchor = GridBagConstraints.WEST;
            c1.insets = new Insets (10, 10, 0, 10);
            c1.gridwidth = GridBagConstraints.REMAINDER;
            c1.gridheight = 1;
            c1.weightx = 0;
            c1.weighty = 0;

            JLabel areaLabel = new JLabel ("Text Area");
            win.add (areaLabel, c1);

            JTextArea textArea = new JTextArea();
            textArea.setFont(new Font("Courier", Font.PLAIN, 12));
            textArea.setText("Text Area text for test, and ");
            textArea.insert("inserted text for test.", 29);
            win.add (textArea, c1);
            textArea.setEditable(false);

            JLabel fieldLabel = new JLabel ("Text Field");
            win.add (fieldLabel, c1);

            JTextField textField = new JTextField (30);
            textField.setFont(new Font("Courier", Font.PLAIN, 12));
            textField.setText("Text Field text for test");
            win.add (textField, c1);
            textField.setEditable(false);
         }

         public static void main (String argv[]) {
            new PasteBug().setVisible(true);
         }
      }
      (Review ID: 97922)
      ======================================================================

      Name: skT88420 Date: 01/06/2000


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-001, native threads, symcjit)

      - Display a JTextField or JTextArea which has .setEditable(false) method called.
      - Attempt to paste any text into it.
      The current text can be selected and over-written with pasting.

      Side note: You can also copy from these fields using Ctrl-C, but the system
      bell goes when you do.
      (Review ID: 99686)
      ======================================================================

      Name: tb29552 Date: 01/25/2000


      java version "1.2.2"
      Classic VM(build JDK-1.2.2-2,native threads,symcjit)


      I declare a JTextFild or JTextArea component and call its method "setEditable
      (false)" to make sure that user can't change its value when needed.
      After application runs,user can input nothing into this JTextField or JTextArea
      component by keyboard,but he can paste text into this "uneditable "component.
      The AWT component TextField and TextArea havn't this bug.
      (Review ID: 100324)
      ======================================================================

            tprinzing Tim Prinzing (Inactive)
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: