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

disappearing text in JDK 1.2.1

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.2
    • 1.2.0, 1.3.0
    • docs
    • 1.2.2
    • x86, sparc
    • solaris_2.6, windows_nt
    • Verified

      Feature Request
      ---------------

      With AWT components, if the background color is set to white, it behaves well on Win32 and Solaris CDE, but not on Solaris OpenWindows. On OpenWindows both the background color and foreground color end up white, resulting in a blank component.

      Could we do anything inside JDK to detect this and/or at least issue a
      warning message? For example, on CDE, when JDK detects which WM is
      being used, or when using XmCreateDrawingArea to find out the
      system default background and foreground colors, or when detecting
      the application is not set the fg and bg colors appropriately, JDK
      issues a warning message (and/or change the color setting).

      Since a lot of existing applications written during JDK11x times
      don't set both froeground and background colors, these applications
      may have problems when runing with JDK1.2. The users often don't
      have the the source (just bytecodes) and thus will have no way of
      modifying the application behavior. Even if they do have the source,
      they'll be irritated by one platform behaving differently than other
      platforms.

      So, could we make a fix to this inside JDK?

      Guanshan



      Guanshan,

      I wrote a test case (ColorTest.java) for this and now I know what you're talking
      about. For native awt components, the foreground and background colors are in
      fact grabbed from the system defaults. This is the intended behavior - the awt
      Toolkit uses XmCreateDrawingArea to create a dummy widget and then finds out the
      background and foreground colors of it. These colors are then used for all (or
      perhaps most) widgets. This makes the Java application "blend" in with the
      operating system color style.

      The real problem is that your application is setting the background color and
      assuming the value of the foreground color, when this value is actually not
      predefined. Note that this same pitfall exists on Win32 and CDE (and in Swing
      under all OSes), if you do a setForeground(Color.white) but do not change the
      background color. What I would suggest is to use both setForeground and
      setBackground.

      If you use Swing components, there isn't this difference across OSes/Window
      Managers. I wrote a second test case (ColorTestSwing.java) which shows that
      with Swing components the default foreground and background colors are
      consistent across all three of Win32, CDE, and OpenWindows.

      Brian


      //-----------------------------ColorTest.java------------------------------
      import java.awt.*;
      import java.awt.event.*;

      public class ColorTest
      {
          public static void main(String[] args) {
              new ColorTest();
          }
          public ColorTest() {
              Frame f = new Frame("Color Test");

              f.setBackground(Color.blue);
              f.setForeground(Color.white);

              f.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent evt) {
                      System.exit(0);
                  }
              });
              f.setLayout(new GridLayout(8,1));

              TextField tf1 = new TextField("White on black");
              tf1.setForeground(Color.white);
              tf1.setBackground(Color.black);
              f.add(tf1);

              TextField tf2 = new TextField("Blue on white");
              tf2.setForeground(Color.blue);
              tf2.setBackground(Color.white);
              f.add(tf2);

              TextField tf3 = new TextField("White on blue");
              tf3.setForeground(Color.white);
              tf3.setBackground(Color.blue);
              f.add(tf3);

              TextField tf4 = new TextField("White on default");
              tf4.setForeground(Color.white);
              //tf4.setBackground(Color.blue);
              f.add(tf4);

              TextField tf5 = new TextField("Blue on default");
              tf5.setForeground(Color.blue);
              //tf5.setBackground(Color.blue);
              f.add(tf5);

              TextField tf6 = new TextField("Default on white");
              //tf6.setForeground(Color.white);
              tf6.setBackground(Color.white);
              f.add(tf6);

              TextField tf7 = new TextField("Default on blue");
              //tf7.setForeground(Color.white);
              tf7.setBackground(Color.blue);
              f.add(tf7);

              TextField tf8 = new TextField("Default on default");
              //tf8.setForeground(Color.white);
              //tf8.setBackground(Color.blue);
              f.add(tf8);

              f.pack();
              f.setVisible(true);
          }
      }



      //------------------------------ColorTestSwing.java-------------------------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;


      public class ColorTestSwing
      {
          public static void main(String[] args) {
              new ColorTestSwing();
          }
          public ColorTestSwing() {
              JFrame f = new JFrame("Color Test Swing");

              f.setBackground(Color.blue);
              f.setForeground(Color.white);

              f.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent evt) {
                      System.exit(0);
                  }
              });
              Container pane = f.getContentPane();
              pane.setLayout(new GridLayout(8,1));

              JTextField tf1 = new JTextField("White on black");
              tf1.setForeground(Color.white);
              tf1.setBackground(Color.black);
              pane.add(tf1);

              JTextField tf2 = new JTextField("Blue on white");
              tf2.setForeground(Color.blue);
              tf2.setBackground(Color.white);
              pane.add(tf2);

              JTextField tf3 = new JTextField("White on blue");
              tf3.setForeground(Color.white);
              tf3.setBackground(Color.blue);
              pane.add(tf3);

              JTextField tf4 = new JTextField("White on default");
              tf4.setForeground(Color.white);
              //tf4.setBackground(Color.blue);
              pane.add(tf4);

              JTextField tf5 = new JTextField("Blue on default");
              tf5.setForeground(Color.blue);
              //tf5.setBackground(Color.blue);
              pane.add(tf5);

              JTextField tf6 = new JTextField("Default on white");
              //tf6.setForeground(Color.white);
              tf6.setBackground(Color.white);
              pane.add(tf6);

              JTextField tf7 = new JTextField("Default on blue");
              //tf7.setForeground(Color.white);
              tf7.setBackground(Color.blue);
              pane.add(tf7);

              JTextField tf8 = new JTextField("Default on default");
              //tf8.setForeground(Color.white);
              //tf8.setBackground(Color.blue);
              pane.add(tf8);

              JButton b1 = new JButton("Dummy Button")

            asommere Alan Sommerer (Inactive)
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: