Best viewed in 1024 X 800 resolution... Leave a comment if u like an article...
Google
 
Web tezcols.blogspot.com

Wednesday, August 30, 2006

Swing textarea with multi styles

Many of us don't find a textarea in swing that supports various styles at a time.But we have.Wil u bliv if i say tht u can use JTextPane to show letters with multi colors and styles.Below given is a novice program to do that.Better go for a menubar if u need several styles.StyledEditorKit allows to add several styles to JTextPane.

/**
* @author Tez K N V
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.StyledEditorKit;

public class TryColorBut extends JFrame{
JButton butRedColor;
JButton butBlueColor;
JButton butBold;
JButton butSize;
JTextPane txtPaneArea;
JScrollPane scrPane;
public TryColorBut(){
getContentPane().setLayout(new FlowLayout());
butRedColor=new JButton(new StyledEditorKit.ForegroundAction("Red",Color.red));
butBlueColor=new JButton(new StyledEditorKit.ForegroundAction("Blue",Color.blue));
butBold=new JButton(new StyledEditorKit.BoldAction());
butSize=new JButton(new StyledEditorKit.FontSizeAction("Large",18));
txtPaneArea=new JTextPane();
scrPane=new JScrollPane(txtPaneArea);
scrPane.setPreferredSize(new Dimension(200,200));
getContentPane().add(scrPane);
getContentPane().add(butRedColor);
getContentPane().add(butBlueColor);
getContentPane().add(butBold);
getContentPane().add(butSize);
setSize(500,300);
}
public static void main(String d[]){
new TryColorBut().setVisible(true);
}
}


tezcols

Labels:

0 Comments:

Post a Comment

<< Home