? format jlabel in html
How come the code could not understand HTML?
somebody please help
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class CreateAccount extends JPanel
implements Serializable, ActionListener {
private JTextField tfName = new JTextField ();
private JTextField tfIC = new JTextField ();
private JTextField tfAddress1 = new JTextField ();
private JTextField tfAddress2 = new JTextField ();
public CreateAccount (){
init();
}
//initialise all the fields
private void init (){
Box content = Box.createVerticalBox();
content.add ( Box.createGlue());
content.add (getFormatedTextField (tfName , "Name" , true) );
content.add (Box.createVerticalStrut(15));
content.add (getFormatedTextField (tfIC , "IC" , true) );
content.add (Box.createVerticalStrut(15));
content.add (getFormatedTextField (tfAddress1 , "Address1" , true) );
content.add (Box.createVerticalStrut(15));
content.add (getFormatedTextField (tfAddress2 , "Address2" , true) );
content.add (Box.createVerticalStrut(15));
content.add ( Box.createGlue());
add(content, BorderLayout.CENTER);
}
private Box getFormatedTextField (JTextField tfField, String fieldName,
boolean isCompulsory){
try{
//a string to format the label
String labelName = new String();
//Create Box for the field
Box row = Box.createHorizontalBox();
row.add (Box.createGlue());
//format the label using HTML
/*if(isCompulsory){
labelName = " <font color = red size = 5> * </font> ";
}
*/
labelName += "<font color= black size = 5 >";
labelName += fieldName ;
labelName += " : </font>";
//add the label to the box
JLabel lbField = new JLabel();
lbField.setText(labelName);
row.add ( lbField );
row.add ( Box.createHorizontalStrut(10));
row.add ( tfField);
row.add ( Box.createGlue());
return row; //success
}
catch(Exception e){
System.out.println("Exception occured while formating text field \n"
+ e );
return null;
}
}
public void actionPerformed (ActionEvent e){
Object source = e.getSource();
}
}

