Hi
I have a JEditorPane which I use to edit html text on. I want to be able to
select a range of the text and make changes to the font/fontsize and so on.
It works with underline, bold, fontsize but strange enough it does not work
with the FontFamily.
Here is my code in question, please tell me if something more is needed...
Thanks.
Keymap parent = editor.getKeymap();
Keymap map = JEditorPane.addKeymap("FontStyleMap", parent);
// Add CTRL-B for Bold
KeyStroke boldStroke = KeyStroke.getKeyStroke(KeyEvent.VK_B,
InputEvent.CTRL_MASK, false);
map.addActionForKeyStroke(boldStroke, new StyledEditorKit.BoldAction());
// Add CTRL-U for Underline
KeyStroke underlineStroke = KeyStroke.getKeyStroke(KeyEvent.VK_U,
InputEvent.CTRL_MASK, false);
map.addActionForKeyStroke(underlineStroke, new
StyledEditorKit.UnderlineAction());
// Add CTRL-M for Monospaced font
KeyStroke monospaceStroke = KeyStroke.getKeyStroke(KeyEvent.VK_M,
InputEvent.CTRL_MASK, false);
map.addActionForKeyStroke(monospaceStroke, new
StyledEditorKit.FontFamilyAction("Courier New", "Courier New"));
editor.setKeymap(map);
shstein2002@yahoo.com - 29 Mar 2005 16:01 GMT
Could the problem have to do with ctrl-M being the same as the enter
key (it could be return on your keyboard :)? Perhaps try a different
key?
Henrik Skovgaard - 30 Mar 2005 08:27 GMT
> Could the problem have to do with ctrl-M being the same as the enter
> key (it could be return on your keyboard :)? Perhaps try a different
> key?
Thanks for your reply, but it does not help using another key-sequence.. Any
other ideas? :-)
John McGrath - 31 Mar 2005 02:36 GMT
> Thanks for your reply, but it does not help using another key-sequence..
> Any other ideas? :-)
My first guess would be that the problem is related to the Action, not the
KeyStroke. Have you tried switching the bindings? In other words, bind
Ctrl-B to FontFamilyAction and Ctrl-M to BoldAction. This would tell you
if the problem is with the keystroke or with the action.

Signature
Regards,
John McGrath