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

Setting background color in TextField

XMLWordPrintable

    • x86
    • windows_95, windows_nt



      Name: sg39081 Date: 08/15/97


      import java.awt.*;

      public class testTextField extends Frame {
          public static void main (String[] args) {
              Frame f = new testTextField ();
              f.setSize (300, 200);
              f.show ();
          }
          
          public testTextField () {
              setLayout (new FlowLayout ());
              TextField redTF = new TextField (5);
              redTF.setBackground (Color.red);
              
              // The following my be a potential bug in JDK 1.1.3. When I try
              // to set the background color as red for the textfield it works
              // fine. However, when I try to set the background color to
              // lightGray, it doesn't work. Why?
              TextField lightGrayTF = new TextField (5);
              lightGrayTF.setBackground (Color.lightGray);
              add (redTF);
              add (lightGrayTF);
          }
      }

      company - Malani , email - ###@###.###
      ======================================================================

      /**
      * the TextField with "lightGray" background shows up white!
      *
      * win95, jdk1.1.3, appletviewer
      */
      import java.awt.*;
      import java.applet.Applet;

      public class texttest extends Applet {
       public void init() {
        TextField tf1 = new TextField("should be lightGray");
        TextField tf2 = new TextField("should be red");
        TextField tf3 = new TextField("is almost lightGray");

        setBackground(Color.lightGray);

         tf1.setBackground(Color.lightGray );
         tf2.setBackground(Color.red );
         tf3.setBackground(new Color(145,145,145));


         add(tf1);
         add(tf2);
         add(tf3);

         invalidate();
         getParent().validate();
        }
      }

      =====================================================================


      the TextField and TextArea use a color model which is not from this
      galaxis.

      Here is my example program :
      import java.awt.*;
      import java.applet.*;

      public class xx extends Applet
      {
         public xx()
         {
           TextField tf;
           tf = new TextField("", 8);
           tf.setBackground( new Color(104,194,248));

           add( tf);
           setBackground( new Color(104,194,248));
         } // xx
      }

      The color from the applet is not the color of the TextField.
      Capture the color and you didn't beleave what you see.

            ehawkessunw Eric Hawkes (Inactive)
            sgoodsunw Sheri Good (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: