United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4733661 : StrikeThrough and Underline text in JTextPane does not show StrikeThrough

Details
Type:
Bug
Submit Date:
2002-08-19
Status:
Resolved
Updated Date:
2002-11-16
Project Name:
JDK
Resolved Date:
2002-11-16
Component:
client-libs
OS:
windows_2000
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.1
Fixed Versions:
1.4.2 (mantis)

Related Reports

Sub Tasks

Description

Name: jk109818			Date: 08/19/2002


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

AND

java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

AND

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

FULL OPERATING SYSTEM VERSION :Microsoft Windows 2000
[Version 5.00.2195]


A DESCRIPTION OF THE PROBLEM :
Insert a text with "Strike Through" and "Underline" both
attributes set in a JTextPane. Only the underline is seen,
the horizontal "Strike Through line" is not seen.

There is no visible difference between these two categories
of text in a JTextPane -
a) the text with only the underline
b) the text with Underline and StrikeThrough

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Compile the pasted code.
2.execute the same with "java MyFrame".
3.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Strike through effect should also be visible. There should
be two horizontal lines to the text. One at the bottom,
another at approx half the height of the text.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;

class MyFrame extends JFrame
{
	StyleContext sc = new StyleContext();
	DefaultStyledDocument doc = new DefaultStyledDocument( sc );

	public MyFrame()
	{
		setSize( 800, 250 );
		getContentPane().setLayout( new BorderLayout() );

		JPanel p = new JPanel(new BorderLayout());
		p.add(new JTextPane(doc), BorderLayout.CENTER);

		getContentPane().add( p, "Center" );

		Style s = null;
		s = sc.addStyle("underlined", null);
		StyleConstants.setFontFamily( s, "Dialog" );
		StyleConstants.setFontSize( s, 24 );
		StyleConstants.setBold( s, false );
		StyleConstants.setItalic( s, false );
		StyleConstants.setUnderline( s, true );
		StyleConstants.setStrikeThrough( s, false );
		try
		{
			doc.insertString( 0, "The text has underline
only.\n\n", s);
		}catch (Exception e)
		{
		}


		s = sc.addStyle("onlySriked", null);
		StyleConstants.setFontFamily( s, "Dialog" );
		StyleConstants.setFontSize( s, 24 );
		StyleConstants.setBold( s, false );
		StyleConstants.setItalic( s, false );
		StyleConstants.setUnderline( s, false );
		StyleConstants.setStrikeThrough( s, true );
		try
		{
			doc.insertString( doc.getLength(), "This text has
strike through effect only.\n\n", s);
		}catch (Exception e)
		{
		}

		s = sc.addStyle("both", null);
		StyleConstants.setFontFamily( s, "Dialog" );
		StyleConstants.setFontSize( s, 24 );
		StyleConstants.setBold( s, false );
		StyleConstants.setItalic( s, false );
		StyleConstants.setUnderline( s, true );
		StyleConstants.setStrikeThrough( s, true );
		try
		{
			doc.insertString( doc.getLength(), "This text has
underline and strike through both, but only underline is seen!!.", s);
		}catch (Exception e)
		{
		}

		show();
	}

	public static void main(String s[])
	{
		new MyFrame();
	}
}
---------- END SOURCE ----------
(Review ID: 160117) 
======================================================================

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis

FIXED IN:
mantis

INTEGRATED IN:
mantis
mantis-b08


                                     
2004-06-14
EVALUATION



Name: ik75403			Date: 10/21/2002




GlyphView.java handles either underline or strike attribute.
The fix is simple:

*** GlyphView.java	2002/10/18 14:25:09	1.1
--- GlyphView.java	2002/10/18 14:27:19
***************
*** 421,432 ****
  	    int d = (int) painter.getDescent(this);
  	    int y = alloc.y + alloc.height - (int) painter.getDescent(this);
  	    if (underline) {
! 		y += 1;
! 	    } else if (strike) {
  		// move y coordinate above baseline
! 		y -= (int) (painter.getAscent(this) * 0.3f);
  	    }
! 	    g.drawLine(x0, y, x1, y);
  	}
      }
  
--- 421,437 ----
  	    int d = (int) painter.getDescent(this);
  	    int y = alloc.y + alloc.height - (int) painter.getDescent(this);
  	    if (underline) {
! 		int yTmp = y;
! 		yTmp += 1;
! 		g.drawLine(x0, yTmp, x1, yTmp);
! 	    } 
! 	    if (strike) {
! 		int yTmp = y;
  		// move y coordinate above baseline
! 		yTmp -= (int) (painter.getAscent(this) * 0.3f);
! 		g.drawLine(x0, yTmp, x1, yTmp);
  	    }
! 
  	}
      }
  




======================================================================
                                     
2004-06-11



Hardware and Software, Engineered to Work Together