Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4248210
Votes 1
Synopsis HTML text in JComponent does not use LnF's foreground color
Category java:classes_swing
Reported Against 1.1.7
Release Fixed 1.3(kestrel)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 21-JUN-1999
Description




create a Jlabel using the html tags. 
do not set the foreground/background colors 
via the html
 The text will show up black. If you have a Look and Feel
 that has a 
black/dark background, the text cannot be read.
 I cannont set explicitly set the 
color because the LnF could
 be switched back to a light background - which 
would cause
 light colored text to be difficult to read.

Code:

package solipsys.lf.plutonium;

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

public class Test {

  static JFrame foo;
  public static void main( String[] arg )
  {
    try {
      UIManager.setLookAndFeel( "solipsys.lf.plutonium.PlutoniumLookAndFeel" );
    } catch ( Exception e ) { }

    foo = new JFrame( "HTML TAG TEST" );
    foo.setSize( 500, 200 );

    foo.getContentPane().setLayout( new GridLayout( 3, 1 ) );

    foo.getContentPane().add( new JLabel( "You Can Read this. There is a label beneath this too." ));
    foo.getContentPane().add( new JLabel( "<html><body> Can You Read This? </a></body></html>" ));


    JButton sw = new JButton( "Switch to Motif" );
    sw.addActionListener( new ActionListener() {
        public void actionPerformed( ActionEvent evt ) {
        try {
              UIManager.setLookAndFeel( "com.sun.java.swing.plaf.motif.MotifLookAndFeel" );
              SwingUtilities.updateComponentTreeUI( foo );
        } catch ( Exception e ) { e.printStackTrace(); }

      }
    });

    foo.getContentPane().add(sw );
    foo.setVisible( true );


  }
}


package solipsys.lf.plutonium;

import javax.swing.plaf.metal.*;
import javax.swing.plaf.*;
import javax.swing.*;
import java.awt.*;

public class PlutoniumTheme extends MetalTheme {

  private final ColorUIResource primary1 = new ColorUIResource(100, 100, 100);
  private final ColorUIResource primary2 = new ColorUIResource(150, 150, 150);
  private final ColorUIResource primary3 = new ColorUIResource(175, 175, 175);
  private final ColorUIResource primary4 = new ColorUIResource(200, 200, 200);

  private final ColorUIResource secondary1 = new ColorUIResource( 0, 0, 0 );//101
  private final ColorUIResource secondary2 = new ColorUIResource( 0, 0, 0 );//20  private final ColorUIResource secondary3 = new ColorUIResource( 0, 0, 0 );//40  private final ColorUIResource secondary4 = new ColorUIResource( 0, 0, 0 );//80
  private FontUIResource controlFont;
  private FontUIResource systemFont;
  private FontUIResource userFont;
  private FontUIResource smallFont;

  public String getName() { return "Plutonium"; }

  public PlutoniumTheme() {

    try {
      controlFont = new FontUIResource(Font.getFont("swing.plaf.metal.controlFont", new Font("Dialog", Font.PLAIN, 12)));
      systemFont = new FontUIResource(Font.getFont("swing.plaf.metal.systemFont", new Font("Dialog", Font.PLAIN, 12)));
      userFont = new FontUIResource(Font.getFont("swing.plaf.metal.userFont", new Font("Dialog", Font.PLAIN, 12)));
      smallFont = new FontUIResource(Font.getFont("swing.plaf.metal.smallFont",
new Font("Dialog", Font.PLAIN, 10)));
    } catch (Exception e) {
      controlFont = new FontUIResource("Dialog", Font.PLAIN, 12);
      systemFont =  new FontUIResource("Dialog", Font.PLAIN, 12);
      userFont =  new FontUIResource("Dialog", Font.PLAIN, 12);
      smallFont = new FontUIResource("Dialog", Font.PLAIN, 10);
    }
  }

// these are blue in Metal Default Theme
  protected ColorUIResource getPrimary1() { return primary1; }
  protected ColorUIResource getPrimary2() { return primary2; }
  protected ColorUIResource getPrimary3() { return primary3; }
  protected ColorUIResource getPrimary4() { return primary4; }

  // these are gray in Metal Default Theme
  protected ColorUIResource getSecondary1() { return secondary1; }
  protected ColorUIResource getSecondary2() { return secondary2; }
  protected ColorUIResource getSecondary3() { return secondary3; }
  protected ColorUIResource getSecondary4() { return secondary4; }
public FontUIResource getControlTextFont() { return controlFont;}
  public FontUIResource getSystemTextFont() { return systemFont;}
  public FontUIResource getUserTextFont() { return userFont;}
  public FontUIResource getMenuTextFont() { return controlFont;}
  public FontUIResource getWindowTitleFont() { return controlFont;}
  public FontUIResource getSubTextFont() { return smallFont;}


  public ColorUIResource getControl() { return getSecondary3(); }
  public ColorUIResource getControlShadow() { return getSecondary2(); }
  public ColorUIResource getControlDarkShadow() { return getSecondary1(); }
  public ColorUIResource getControlInfo() { return getWhite(); }
  public ColorUIResource getControlHighlight() { return getSecondary4(); }
  public ColorUIResource getControlDisabled() { return getSecondary2(); }

  public ColorUIResource getPrimaryControl() { return getPrimary3(); }
  public ColorUIResource getPrimaryControlShadow() { return getPrimary2(); }
  public ColorUIResource getPrimaryControlDarkShadow() { return getPrimary1(); }
  public ColorUIResource getPrimaryControlInfo() { return getBlack(); }
  public ColorUIResource getPrimaryControlHighlight() { return getWhite(); }

  public ColorUIResource getSystemTextColor() { return getPrimary1(); }
  public ColorUIResource getControlTextColor() { return getControlInfo(); }
  public ColorUIResource getInactiveControlTextColor() { return getControlDisabled(); }
  public ColorUIResource getInactiveSystemTextColor() { return getSecondary2();
}
  public ColorUIResource getUserTextColor() { return getBlack(); }
  public ColorUIResource getTextHighlightColor() { return getPrimary3(); }
  public ColorUIResource getHighlightedTextColor() { return getControlTextColor(); }

  public ColorUIResource getWindowBackground() { return getWhite(); }
  public ColorUIResource getWindowTitleBackground() { return getPrimary3(); }
  public ColorUIResource getWindowTitleForeground() { return getBlack(); }
  public ColorUIResource getWindowTitleInactiveBackground() { return getSecondary3(); }
  public ColorUIResource getWindowTitleInactiveForeground() { return getBlack(); }

  public ColorUIResource getMenuBackground() { return getSecondary3(); }
  public ColorUIResource getMenuForeground() { return  getBlack(); }
  public ColorUIResource getMenuSelectedBackground() { return getPrimary2(); }
  public ColorUIResource getMenuSelectedForeground() { return getBlack(); }
  public ColorUIResource getMenuDisabledForeground() { return getSecondary2(); }  public ColorUIResource getSeparatorBackground() { return getWhite(); }
  public ColorUIResource getSeparatorForeground() { return getPrimary1(); }
  public ColorUIResource getAcceleratorForeground() { return getPrimary1(); }
  public ColorUIResource getAcceleratorSelectedForeground() { return getBlack(); }

}


ackage solipsys.lf.plutonium;

import java.awt.*;

import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;


/**
 *
 * This look and feel is a deriviative of the Metal Look and Feel.
 * It changes the color to be light on dark and removes the spaces
 * around the buttons.
 *
 * @author Stephen M. Jones
 * @version Solipsys Corporation
 **/

public class PlutoniumLookAndFeel extends MetalLookAndFeel {

  public String getName()
  {
    return "Plutonium";
  }

  public String getID()
  {
    return "Plutonium";
  }

  public String getDescription()
  {
    return "The Solipsys Plutonium Look and Feel";
  }

  protected void initComponentDefaults( UIDefaults table )
  {
    super.initComponentDefaults( table );

    Object buttonBorder =  new BorderUIResource( new MetalBorders.ButtonBorder() );

    Object[] overrides = new Object[] {
      "Button.border", buttonBorder 
      };

    table.putDefaults( overrides );
  }
protected void createDefaultTheme()
  {
    setCurrentTheme( new PlutoniumTheme());
  }
}
(Review ID: 84615) 
======================================================================
Work Around
N/A
Evaluation
As the submitter points out, the html support does not pick up the background/foreground/font from the component it is in. This should be changed (although at this point changing it to pick up the colors might cause developers confusion).
 xxxxx@xxxxx  1999-09-16

Ok, BasicDocument (a subclass of HTMLDocument) now registers a special subclass of Color for the body foreground color. When getForeground is invoked if the return value is this special color, implying the developer hasn't specifically set a color in the html, the foreground from the component is returned.
 xxxxx@xxxxx  1999-10-05
Comments
  
  Include a link with my name & email   

Submitted On 19-AUG-1999
apatacchiola
Suns HTML text implementation doesn't fit in very well
with the way things are done regularly. Supposing
you had specified a color and the UI's L&amp;F was supported,
which color is used in that case. The complete lack
of documentation describing the use of html text 
and it's effects is pretty annoying too. 
Why when
I put html text on a jbutton and then disable it,
is the text not disabled? 
Why can't I have more than one line of text in a label
or button without using html text and without subclassing
the component and using 1 label for each line of text?
I guess Sun never thought &quot;gee maybe people will want to put
more than one line of text on a button and have it
work predictably&quot;.


Submitted On 27-JUN-2000
lblevins
In the latest Swing (it says 1.2.2) I got with JBuilder 
3.5, using HTML text in a JLabel still resulted in the text 
being printed in black.  The setForeground() Color I used 
for the JLabel and the setFont() Font that I set for the 
JLabel did NOT appear when the JLabel was displayed.



PLEASE NOTE: JDK6 is formerly known as Project Mustang