JDK-4148334 : Button background color inheriting from frame
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-06-12
  • Updated: 1999-07-20
  • Resolved: 1999-07-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.1.8 1.1.8Fixed 1.2.2Fixed
Related Reports
Relates :  
Description

Name: chT40241			Date: 06/12/98


The bug is that the background of the Button created looks gray, but it's really inheriting white from the Frame it is contained in.  When the background color is queried from the Button it returns white, but it should return lightgray.  This is confusing since the button background color shows up as white (actually it's the WINDOW SystemColor, which is white on my machine) in the property sheet but is gray in the button.

Here's the output of the program :

Button background color is of type : java.awt.Color
Button background color is  : java.awt.Color[r=255,g=255,b=255]
Button background color RGB is  : -1
Button background color is of type : java.awt.Color
Button background color is  : java.awt.Color[r=255,g=255,b=255]
Button background color RGB is  : -1

Here is the code:

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Bug {
   public static void main( String[] args ) {
      Frame frame = new Frame();
      frame.setLayout( new FlowLayout() );

      Button button = 
        new Button( "Press me to find out my background color" );
      button.addActionListener( new ActionHandler( button ) );
      frame.add( button );

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

class ActionHandler implements ActionListener
{
   Button button;

   public ActionHandler( Button button ) {
      this.button = button;
   }

   public void actionPerformed( ActionEvent event ) {
      System.out.println( "Button background color is of type : :"
                + button.getBackground().getClass().getName() );
      System.out.println( "Button background color is  : " + 
                button.getBackground() );
      System.out.println( "Button background color RGB is  : " +
                button.getBackground().getRGB() );
   }
}

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

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.1.8 FIXED IN: 1.1.8 1.2.2 INTEGRATED IN: 1.1.8 1.2.2 VERIFIED IN: 1.1.8
14-06-2004

WORK AROUND Name: chT40241 Date: 06/12/98 none ======================================================================
11-06-2004

SUGGESTED FIX Name: rpC71689 Date: 11/17/98 prs@russia The idea of the fix is like the following: when creating these components, we should call setBackground method on the appropriate class (java.awt.Button for buttons etc.) with the actual color of the component to synchronize Java's field and peer's field. ======================================================================
11-06-2004

EVALUATION Name: rpC71689 Date: 11/17/98 prs@russia The problem exist not only for buttons, but for the following six awt classes: Button, Choice, List, Scrollbar, TextField and TextArea. In file src/win32/sun/windows/awt_Button.cpp (awt_Choice.cpp etc.) one can find line like c->m_backgroundColorSet = TRUE; // suppress inheriting parent's color. in method AwtButton::Create. The same for other five files. So these components do not inherit parent's background color on windows, but are painted with the default color. But the background field of appropriate Java class stays null, so when one calls getBackground method on, say, Button, the color is taken from parent. That's why though Button stays grey, getBackground returns parent's background color. ====================================================================== Verified the problem as fixed, however the regression test is not up to spec. Will notify the awt team, but the bug is fixed. Verified via direct use of java. Causes error using JavaTest 2.0. john.s.lee@Eng 1999-01-21
21-01-1999