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

Motif TextItem colors not handled properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1
    • client-libs
    • None
    • sparc
    • solaris_2.5.1



      Name: mc57594 Date: 01/30/97


      The following code works fine on Win95 but does not work
      correctly on Solaris. This was not working correctly under the Beta2
      release either. Since I didn't see this on the list of known bugs, I'm
      resubmitting it.
      To demo the problem, move to either TextItem displayed by this code and
      enter something which is not a valid integer. The text should change
      color. Instead, there is very strange behavior which the code should
      illustrate.
      Since this works exactly the way I intend on Win95, I'm assuming that
      this is a bug and not something I'm messing up myself.
      CODE START
      **********
      import java.awt.*;
      import java.awt.event.*;
      class TextInteger extends TextField {
         Integer value = null;
         boolean error_color_on = false;
         Color text_color = null;
      public TextInteger () {
         this(null);
      }
      public TextInteger (int i) {
         this(new Integer (i));
      }
      public TextInteger (Integer i) {
         super (10);
         enableEvents (AWTEvent.FOCUS_EVENT_MASK);
         setInteger (i);
      }
      public void setInteger (Integer i) {
         if (i != null)
            setText (i.toString());
         else
            setText (" ");
         value = i;
      }
      public Integer getInteger () {
         return value;
      }
      public void processFocusEvent (FocusEvent e) {
         switch (e.getId()) {
         case FocusEvent.FOCUS_LOST:
            boolean error = false;
            int i;
            String svalue;
            svalue = getText ().trim();
            if (svalue.equals(""))
      return;
            try {
      i = Integer.parseInt (svalue);
            }
            catch (NumberFormatException e1) {
      setForeground (Color.red);
      error = true;
      error_color_on = true;
      repaint ();
      requestFocus ();
      return;
            }
            if (! error && error_color_on) {
      setForeground (text_color);
      error_color_on = false;
      repaint ();
            }
            value = new Integer (i);
            break;
         case FocusEvent.FOCUS_GAINED:
            if (text_color == null)
      text_color = getForeground ();
            break;
         }
         super.processFocusEvent (e);
      }
      public static void main (String[] args) {
         Frame f = new Frame ("Test TextInteger");
         TextInteger ti = new TextInteger (new Integer(15));
         TextInteger ti2 = new TextInteger ();
         f.setLayout(new BorderLayout ());
         f.add ("North", ti);
         f.add ("South", ti2);
         f.pack ();
         f.show ();
      }
      }
      Rob Janes
      Cummins Engine Company
      ###@###.###
      (812) 377-7328
      ======================================================================

            xdengsunw Xianfa Deng (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: