Using StyledTextArea from an applet.
- By Budi Kurniawan
- November 14, 2000
COMPONENT JAVA
AWT Styled Text Component
Budi Kurniawan
Listing 2. Using StyledTextArea from an applet.
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet {
int width = 200;
StyledTextArea styledTextArea = new
StyledTextArea(width);
ScrollPane scrollPane = new ScrollPane();
Font font1 = new Font("arial", 0, 14);
Font font2 = new Font("arial", 2, 16);
Font font3 = new Font("monospaced", 3, 20);
public Applet1() {
try {
init();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void init() throws Exception {
this.setLayout(null);
scrollPane.setBackground(Color.white);
scrollPane.setBounds(new Rectangle(0, 0,
width, 200));
styledTextArea.setBounds(new Rectangle(0,
0, width, 0));
add(styledTextArea, null);
styledTextArea.setBounds(0,0,width,0);
add(scrollPane, null);
scrollPane.add(styledTextArea);
styledTextArea.append("The main advantage
of using the StyledTextArea component
is . . .", font1, Color.blue);
styledTextArea.append("you can make your
text colorful.", font2, Color.red);
styledTextArea.append("But that is not
the only one.", font3, Color.magenta);
}
}
About the Author
Budi Kurniawan is an independent consultant who is currently working on a project for Kidz.net Ltd. in Sydney, Australia. He can be contacted at [email protected].