Hello Friends,
Below I have given the code all attributes like bold,background color is working fine but not the linespacing attribute.
Could u pl.. help me out in this regard.
public class Sample extends JFrame {
private JTextPane jTextPane1 = new JTextPane();
JTextPane jt2=new JTextPane();
StyledDocument doc=null;
String as="<html><head></head><body>This is first line.This is second line.This is thrid line.This is first line.This is second line.This is thrid line.</body></html>";
public Sample() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jt2.setBounds(150,0,150,350);
jt2.setContentType("text/html");
jt2.setOpaque(false);
Color white=new Color(255,255,255);
MutableAttributeSet set=new SimpleAttributeSet();
jt2.setText(as);
jt2.setBorder(javax.swing.border.LineBorder.createBlackLineBorder());
JLabel jlab=new JLabel();
doc=jt2.getStyledDocument();
int len=jt2.getDocument().getLength();
javax.swing.text.StyleConstants.setLineSpacing(set,25.25f);
javax.swing.text.StyleConstants.setBackground(set,white);
javax.swing.text.StyleConstants.setSpaceAbove(set,95.5f);
javax.swing.text.StyleConstants.setBold(set,true);
doc.setCharacterAttributes(0,len,set,false);
this.getContentPane().add(jt2);
}
public static void main(String args[])
{
Sample fr2=new Sample();
fr2.setSize(500,500);
fr2.setVisible(true);
}
}
Thanks & regards,
Nivi.