JDK-5037834 : Repaint issue if we set html having color setting as text on JRadioButton
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-04-26
  • Updated: 2006-05-23
Related Reports
Relates :  
Relates :  
Description

Name: jl125535			Date: 04/26/2004


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

java version "1.4.1_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_03-b02)
Java HotSpot(TM) Client VM (build 1.4.1_03-b02, mixed mode)

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

A DESCRIPTION OF THE PROBLEM :
I've a few JRadioButtons in my panel. One JRadioButton has associated text which is longer and can't be displayed in one line. So I pass html string in as setText argument for the JRadioButton.
Enabling/disabling of radiobuttons is determines by the state of a JCheckBox.
  To appropriately display enabling /disabling of JRadioButtons, I have to call JRadioButton.setText with html string having different colors.
Repeated selecion change of JCheckbox shows some flickering in radio ButtonGroup. The radiobuttons text seems to jump one line above beween transitions.

I have observed that the problem appears only if one JRadioButton in buttonGroup has more than one line of text and html has some font color settings.If either of these conditions is missing, the issue doesn't appear.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code below:
Repeatedly click on JCheckBox.
Some flickering will be seen in radio ButtonGroup. The radiobuttons text seems to jump one line above beween transitions.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JRadioButtons text shouldn't jump.
ACTUAL -
Some flickering isseen in JRadioButtons ButtonGroup. The radiobuttons text seems to jump one line above beween transitions.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;

public class RadioTest extends JFrame implements ActionListener
{ 
  public static void main(String[] args)
  {
     RadioTest test = new RadioTest();
     test.getContentPane().setLayout(new BorderLayout());
     test.init();
    
 
    test.setSize(200,300);
    test.setVisible(true);
  }
  public void init()
  {
     JPanel panel = new JPanel();
     panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
     
     longString = "Some very long text that requires wrapping onto different lines." ;
     String htmlstart =
      "<HTML><BODY><FONT COLOR=\"#000000\">";

     String htmlend = "</FONT></BODY></HTML>";

     String html = htmlstart +longString + htmlend;

     button1 = new JRadioButton(html);
     button2 = new JRadioButton(htmlstart + "Some text" + htmlend);
     button3 = new JRadioButton(htmlstart + "Some more text" + htmlend);
     
     ButtonGroup b = new ButtonGroup();
     b.add(button1);
     b.add(button2);
     b.add(button3);
     
     panel.add(button1);
     panel.add(button2);
     panel.add(button3);
          
     box = new JCheckBox("Enable all radios");
     box.addActionListener(this);
    
     panel.add(box);
     getContentPane().add(BorderLayout.CENTER, panel);
  }
  public void actionPerformed(ActionEvent e)
  {
    _updateControls();
  }
  private  void _updateControls()
  {
     boolean enableRadioButtons = (box.isSelected() == true)
      ? false : true;
    
    String htmlstart =
      "<HTML><BODY><FONT COLOR=\"#000000\">";
    if(!enableRadioButtons)
    htmlstart =
      "<HTML><BODY><FONT COLOR=\"#666666\">";
    String htmlend = "</FONT></BODY></HTML>";
   
    button1.setText(htmlstart + longString + htmlend);
    button2.setText(htmlstart + "Some text" + htmlend);
    button3.setText(htmlstart + "Some more text " + htmlend);

    // enable/disable the radio buttons
    button1.setEnabled(enableRadioButtons);
    button2.setEnabled(enableRadioButtons);
    button3.setEnabled(enableRadioButtons);

    if(enableRadioButtons)
    {
      button1.setSelected(true);
    }
    else
    {
      button2.setSelected(true);
    }
  }
  JCheckBox box;
  JRadioButton button1;
  JRadioButton button2;
  JRadioButton button3;
  String longString;
} 

---------- END SOURCE ----------
(Incident Review ID: 255087) 
======================================================================

Comments
EVALUATION Name: sh120115 Date: 04/27/2004 Yes, I can see the described behavior. There is something odd with respect to jumpiness when laying out HTML text on components. I can see the same thing in SwingSet2. Every time you switch to the list demo, you see the HTML text at the top flicker as it lays out. ###@###.### 2004-04-27 ====================================================================== Name: anR10225 Date: 05/25/2004 This is a known issue with line-wrapped text components. It's preferred height depends on its width. First time the label is laid out it has preferred size as it is laid out on a single line. Due to the paint() call the label gets its actual width, redo its layout and revalidates the container what causes the flickering. The simplest way to deliver the desired width to the HTML view is to call paint on the component just after setText() call and before the component is revalidated. This makes sense only if the component already has the correct width, i.e. has been already laid out. For the test case described the following workaround may be used : private void _updateControls() { ... button1.setText(htmlstart + longString + htmlend); BufferedImage img= new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); button1.paint(img.getGraphics()); ... } May be this bug should be closed as duplicate. Anyway we will work on this only in the next release. ======================================================================
25-09-2004