The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

About setting font size for html text editor

Posted by Rach on November 07, 2001 at 3:47 PM

Hi!

Does anyone know how I can set the font size of the html text? Suppose I want to set the string "hello" to be +3 in size, I know that in html we can write as below:

hello

This is what I have done to change the size of the text to be +3 but it was wrong.

private static final String[] FONT_SIZE = {
"smallest", "smaller", "small", "medium", "large", "largest" };

private static final Action[] SIZE_ACTION = {
new StyledEditorKit.FontSizeAction("smallest", -3),
new StyledEditorKit.FontSizeAction("smaller", -2),
new StyledEditorKit.FontSizeAction("small", -1),
new StyledEditorKit.FontSizeAction("medium", 0),
new StyledEditorKit.FontSizeAction("large", +1),
new StyledEditorKit.FontSizeAction("larger", +2),
new StyledEditorKit.FontSizeAction("largest", +3) };

And in my JPanel, I added this

final JPopupMenu menu1 = new JPopupMenu();
for(int i=0; i JMenuItem sizeMenu = new JMenuItem();
sizeMenu.setAction(SIZE_ACTION[i]);
sizeMenu.setText(FONT_SIZE[i]);
menu1.add(sizeMenu);
}

final JButton sizeButton = new JButton("size");
sizeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
menu1.pack();
menu1.show(sizeButton, 0, 0);
}
});

When I clicked on the sizeButton, it will popup the sizeMenus that I can choose the size from smallest to largest. But, it doesn't work correctly since it doesn't know what the size of the negative numbers is. And even the positive numbers, it doesn't intepret the size as an html text correctly. Instead, it inteprets as a plain text that has the size of 1, 2, and 3. (which are very very small)

Does anyone know where I have to make change? I think I have to use something else which is not "StyledEditorKit.FontSizeAction" but I have no clue what should it be right now.

Thanks so much,
Rach





Replies:
  • Notice Rach November 07, 2001 at 3:50 PM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us