Since I finally found a solutions I thought you might want me to share. Hope you enjoy.
code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.util.Hashtable;
public class Content{
public static void main(String[] args){
ContentFrame frame = new ContentFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.show();
}
}
class ContentFrame extends JFrame implements ActionListener{
private static final int WIDTH= 640;
private static final int HEIGHT= 480;
private Action boldAction;
private Action italicAction;
private Action underlineAction;
private Action linkAction;
private JButton testOutput;
private JTextPane editorPane;
private JScrollPane scrollPane;
Hashtable actions;
public ContentFrame() {
setTitle("Student Affairs Content Management");
setSize(WIDTH,HEIGHT);
boldAction = new StyledEditorKit.BoldAction();
boldAction.putValue(Action.NAME, "Bold");
italicAction = new StyledEditorKit.ItalicAction();
italicAction.putValue(Action.NAME, "Italic");
underlineAction = new StyledEditorKit.UnderlineAction();
underlineAction.putValue(Action.NAME, "Underline");
testOutput = new JButton("Test Output");
testOutput.addActionListener(this);
JPanel stylePanel = new JPanel();
stylePanel.setLayout(new GridLayout(4,1));
stylePanel.add(new JButton(boldAction));
stylePanel.add(new JButton(italicAction));
stylePanel.add(new JButton(underlineAction));
stylePanel.add(testOutput);
setJMenuBar(createMenuBar());
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(stylePanel,BorderLayout.EAST);
editorPane = new JTextPane();
editorPane.setCaretPosition(0);
editorPane.setMargin(new Insets(5,5,5,5));
editorPane.setContentType("text/html");
editorPane.setEditable(true);
scrollPane = new JScrollPane(editorPane);
scrollPane.setPreferredSize(new Dimension(400,300));
contentPane.add(scrollPane, BorderLayout.CENTER);
createActionTable(editorPane);
}
private void createActionTable(JTextComponent textComponent){
actions = new Hashtable();
Action[] actionsArray = textComponent.getActions();
for (int i = 0; i < actionsArray.length; i++){
Action a = actionsArray[i];
actions.put(a.getValue(Action.NAME), a);
}
}
private Action getActionByName(String name){
return (Action)(actions.get(name));
}
public void actionPerformed(ActionEvent e) {
System.out.println(editorPane.getText());
}
public JMenuBar createMenuBar(){
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
menuBar.add(menu);
JMenuItem menuItem = new JMenuItem("Open");
menuItem.addActionListener(this);
menu.add(menuItem);
menuItem = new JMenuItem("Close");
menuItem.addActionListener(this);
menu.add(menuItem);
menuItem = new JMenuItem("Save");
menuItem.addActionListener(this);
menu.add(menuItem);
menuItem = new JMenuItem("Quit");
menuItem.addActionListener(this);
menu.add(menuItem);
menu = new JMenu("Style");
menuBar.add(menu);
menuItem = new JMenuItem(boldAction);
menu.add(menuItem);
menuItem = new JMenuItem("Italic");
menuItem.addActionListener(this);
menu.add(menuItem);
menuItem = new JMenuItem("Underline");
menuItem.addActionListener(this);
menu.add(menuItem);
return menuBar;
}
}