Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

FontFamilyAction on JEditorPane

Thread view: 
Henrik Skovgaard - 29 Mar 2005 13:19 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.