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

TextField data is displayed in multi lines if mapped from the text of text area.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs



      Name: skT88420 Date: 08/11/99


      TextField data is displayed in multilines if mapped from the data of a textarea. And one of the middle lines are only displayed on the text field. you cannot see the entire data unless you start deleting.
      Actually data should have been displayed in single line with return characters as separators between the data of different lines.
      Steps to reproduce
      ------------------
      1.Copy the sourcecode to MyPanel.java and compile.
      2.Put focus onto TextArea and start typing in some thing. Make sure you have multi lines of data typed in.
      3.Press First Button 'TextAreaToTextField' and see that the data in text area is mapped into the text Field.
      4. notice that only part of the data is visible and mostly one of the middle lines displayed.
      Try traversing through. you cannot traverse through any of the lines other than the visible one.
      Try using backspace to delete .
      see that the initial lines of data appears.

      ALSO:

      TextField is converted to TextArea when data from a text area is mapped in to text field and then text area data is deleted.

      Steps to reproduce.
      ------------------
      1.Copy the soucecode to a file MyPanel.java and compile.
      2.Run the program.
      3.Enter in multi lines of data into text area.
      4.Press first button TextAreaTotextField.
      5.text of text area gets mapped to textfield.
      6.delete data in text area completely, now text field converts itself to text area.


      Source Code
      -----------
      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import java.io.*;
      import javax.swing.*;
      import javax.swing.text.*;
      import javax.swing.event.*;
      import javax.swing.border.*;

      public class MyPanel extends JPanel
      implements java.awt.event.ActionListener
      {
      JButton tst1, tst2;
      JTextField tf;
      JTextArea ta;
      public MyPanel()
      {
      super();
      setSize(100, 400);

      // JPanel ButtonArea = new JPanel();

      tst1 = new JButton("TextAreaToTextField");
      tst1.setActionCommand("TextAreaToTextField");
      tst1.setMnemonic('T');
      tst2 = new JButton("TextFieldToTextArea");
      tst2.setActionCommand("TextFieldToTextArea");
      tst2.setMnemonic('F');
      // ButtonArea.add(tst1);
      // ButtonArea.add(tst2);
      add(tst1);
      add(tst2);

      tf = new JTextField("Test", 20);

      setLayout(new FlowLayout());

      ta = new JTextArea("This is a test", 10,25);

      // add(ButtonArea);
      add(tf);
      add(ta);

              //Listen for actions on buttons 1 and 3.
      tst1.addActionListener(this);
      tst2.addActionListener(this);


      }

          public void actionPerformed(java.awt.event.ActionEvent e)
      {
      System.out.println("action:"+e.getActionCommand());
              if (e.getActionCommand().equals("TextAreaToTextField"))
      {
      tf.setText(ta.getText());
      }
              else if (e.getActionCommand().equals("TextFieldToTextArea"))
      {
      ta.setText(tf.getText());
      }
      }
      public static void main(String[] args) {

      try
      {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
      catch (Exception e)//UnsupportedLookAndFeelException e)
      {}
      JFrame frame = new JFrame("MyPanel");

      WindowListener l = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {System.exit(0);}
      };
      frame.addWindowListener(l);

      frame.getContentPane().add("Center", new MyPanel());
      frame.pack();
      frame.show();

      }

      }
      (Review ID: 93783)
      ======================================================================

            tprinzing Tim Prinzing (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: