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

JTextField does not honor SynthStyle-based setting of "opaque"

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      When applying a SynthStyle to a JTextField, the "opaque" setting is not honored.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a synth XML file and bind a style to the TextField region where the "opaque" setting in that style is set to "false".
      2. Set some unusual background color (like bright green) for the text field so that it will be obvious whether or not it is being painted
      3. Start an application and switch to the Synth UI you created in steps 1 and 2
      4. Observe that the background for the JTextField is painted regardless of the setting of "opaque" in the XML file.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
        From the "Synth File Format" page located at:
      http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/plaf/synth/doc-files/synthFileFormat.html

          "The opaque element indicates whether or not any Components the style is associated with are to be made opaque..."

      I expected that as the above sentence indicates, a JTextField component associated with a style where "opaque" is set to "false" will, in fact, not be opaque.
      ACTUAL -
      The JTextField widget ignores the opacity setting specified in the XML file.

      After looking through the JDK source code for a while I suspect the problem arises from the way that the opacity of a JTextField is set; there are interactions in BasicTextUI.java with the JTextComponent field called "editor" that might possibly be the source of this issue (it seems that the editor, which is inaccessible, might be determining the opacity of the containing JTextField).

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
      SYNTH XML FILE (test.xml):
      ~~~~~~~~~~~~~~
      <synth>
          <style id="style_Default">
              <state>
                  <color type="BACKGROUND" value="#aaaaaa" />
                  <color type="FOREGROUND" value="#000000" />
              </state>
          </style>
          <bind style="style_Default" type="region" key=".*" />

          <style id="style_TextField">
              <opaque value="false" />
              <state>
                  <opaque value="false" />
                  <color type="BACKGROUND" value="#00ff00" />
              </state>
          </style>
          <bind style="style_TextField" type="region" key="TextField" />
      </synth>
      */








      package test;

      import java.awt.Color;
      import java.awt.FlowLayout;
      import java.io.InputStream;

      import javax.swing.JFrame;
      import javax.swing.JTextField;
      import javax.swing.SwingUtilities;
      import javax.swing.UIManager;
      import javax.swing.WindowConstants;
      import javax.swing.border.LineBorder;
      import javax.swing.border.TitledBorder;
      import javax.swing.plaf.synth.SynthLookAndFeel;

      public class TestApp
      {

          public final static void main(String[] args)
          {
              JFrame frame = new JFrame("Test app");
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              JTextField textField = new JTextField("Always opaque...");
              textField.setBorder(new TitledBorder(new LineBorder(Color.BLACK, 2, true), "JTextField"));
              frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
              frame.getContentPane().add(textField);
              frame.pack();
              frame.setBounds(25,25,200,100);
              InputStream xmlStream = TestApp.class.getResourceAsStream("test.xml");
              SynthLookAndFeel synthLaf = new SynthLookAndFeel();
              try
              {
                  synthLaf.load(xmlStream, TestApp.class);
                  UIManager.setLookAndFeel(synthLaf);
              }
              catch (Exception e)
              {
                  e.printStackTrace();
                  System.exit(-1);
              }

              SwingUtilities.updateComponentTreeUI(frame);
              frame.setVisible(true);
              SwingUtilities.updateComponentTreeUI(frame);
              
              System.err.println("JTextField.isOpaque()=" + textField.isOpaque());
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: