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

broken color for disabled combo box's trigger arrorw, and some element surface

    XMLWordPrintable

Details

    • hopper
    • x86
    • windows_nt
    • Verified

    Description

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import java.util.*;

      /**
       *
       * The background color is erroneous for a disabled combo box's trigger
       * arrow, and element surronding surface in the Motif, and the Metal
       * Look and Feel (j2se 1.4.0 beta 2)
       *
       * However, the Windows L&F behavior was handled appropriately through the bug#4250958 fix.
       *
       *
       **/
      public class Test extends JFrame {


          Test(String laf, int location_x, int location_y, int size_x, int size_y, boolean isWorkAround) {
              super();
              String title = laf.substring(laf.lastIndexOf('.')+1);
              title = isWorkAround ? title + " - With workaround": title;
              setTitle (title);
              this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);

              Container content = this.getContentPane();
              content.setLayout(new BoxLayout (content, BoxLayout.Y_AXIS));

              this.setBounds (location_x, location_y, size_x, size_y);
              if (laf != null) {
                try {
                  UIManager.setLookAndFeel(laf);
                } catch (Exception e ) {
                  System.err.println ("Test.Test(): " + e);
                }
              }

              // create the content for the 2 used cumbo boxes.
              Vector items = new Vector();
              items.add("first");
              items.add("second");
              items.add("third");
              items.add("fourth");


            // To change the current Look and Feel for all the JComboBox components,
            // one needs to negotiate with the UIManager.

                // Note that the background and foreground colors for a
                // disabled combo box can only be handled via UIManager
              UIManager.put ("ComboBox.disabledBackground", Color.cyan);
              UIManager.put ("ComboBox.disabledForeground", Color.white);
                // Although the individual component allows us to
                // change the foreground and background colors we
                // will start with known initial colors
              UIManager.put ("ComboBox.background", Color.blue);
              UIManager.put ("ComboBox.foreground", Color.magenta);

            // create the disabled cyan combo box.
              JComboBox combo = new JComboBox(items);



      // Adding this following lines works around the misfit background color
      // for the disabled combo box's trigger arrow, and element surronding
      // surface in the Motif, and the Metal Look and Feel (j2se 1.4.0 beta 2):
      if (isWorkAround == true) {
          combo.setBackground(Color.cyan);
      }

              combo.setEnabled(false);
              content.add(combo);


        // create the enabled cyan combo box.
              combo = new JComboBox(items);
              combo.setBackground(Color.cyan);
              combo.setForeground(Color.magenta);

              content.add(combo);

        // Add a test button to highlight bug#4250958 behavior in j2se 1.3.x
              UIManager.put ("Button.background", Color.red);
              UIManager.put ("Button.foreground", Color.yellow);

              JButton testButton = new JButton();
              testButton.setText("for bug#4250958 in 1.3.x");
              testButton.setAlignmentX(Component.CENTER_ALIGNMENT);
              content.add(testButton);
          }


          public static void main(String args[]) {

            int origin_x = 5;
            int origin_y = 5;
            int size_x = 300;
            int size_y =108;
            int gap =5;

            Test testPanel = new Test("com.sun.java.swing.plaf.windows.WindowsLookAndFeel", origin_x, origin_y, size_x, size_y, false);
            testPanel.setVisible(true);
                 testPanel = new Test("com.sun.java.swing.plaf.motif.MotifLookAndFeel", (origin_x+size_x+gap), origin_y, size_x, size_y, false);
            testPanel.setVisible(true);
                 testPanel = new Test("javax.swing.plaf.metal.MetalLookAndFeel", (origin_x+2*size_x+2*gap), origin_y, size_x, size_y, false);
            testPanel.setVisible(true);

                       testPanel = new Test("com.sun.java.swing.plaf.motif.MotifLookAndFeel", (origin_x+size_x+gap), (origin_y+size_y+gap), size_x, size_y, true);
            testPanel.setVisible(true);
                 testPanel = new Test("javax.swing.plaf.metal.MetalLookAndFeel", (origin_x+2*size_x+2*gap),(origin_y+size_y+gap), size_x, size_y, true);
            testPanel.setVisible(true);

          }
      }

      Attachments

        Issue Links

          Activity

            People

              mdavidsosunw Mark Davidson (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: