underlining a text or a character
hello
I want to underline and make the string "hello" to be. the code is not showing any error but the "hello" string is not changing to RED or UNDERLINED.
can anybody help?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
publicclass TypingTestextends JFrame
{
public TypingTest()
{
super("Typing Test" );
Container cn = getContentPane();
cn.setLayout(null );
JPanel textPanel1, textPanel2;
JTextPane textPane1, textPane2;
//JPanel1
textPanel1 =new JPanel();
textPanel1.setLayout(null );
StringBuffer bf =new StringBuffer("hello" );
textPanel1.setBounds( 0,0,600,300);
textPane1 =new JTextPane();
String s ="";
for(int i = 0; i < bf.length(); i++)
s = s + bf.charAt(i);
Style style = textPane1.addStyle("Red",null);
StyleConstants.setForeground(style, Color.red);
style = textPane1.addStyle("Red Underline", style);
StyleConstants.setUnderline(style,true);
textPane1.setText( s );
textPane1.setBounds( 0,0,600,290);
textPanel1.add( textPane1 );
// Panel2
textPanel2 =new JPanel();
textPanel2.setLayout(null );
textPanel2.setBounds( 0,300,600,300);
textPane2 =new JTextPane();
textPane2.setBounds( 0,0,600,290);
textPanel2.add( textPane2 );
cn.add( textPanel1 );
cn.add( textPanel2 );
setSize( 600, 600 );
setVisible(true );
repaint();
}
publicstaticvoid main( String args[] )
{
TypingTest app =new TypingTest();
app.addWindowListener(
new WindowAdapter(){
publicvoid WindowClosing( WindowEvent we){
System.exit( 0 );
}
}
);
}
}

