获取JEditorPane中选定文本的字体 [英] Get font of selected text in JEditorPane

查看:173
本文介绍了获取JEditorPane中选定文本的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上这个问题说明了这一切;

我有一个内容类型为text / html的JEditiorPane。我创建了一个字体家族和字体大小的组合框,并使用StyledEditorKit操作启用它们。这很好,我可以改变选定文本的字体属性(你做了什么...)

唯一的是当我选择文本有点混淆因为ComboBox仍然显示用户以前的选择。我很想实现功能,根据选定的文本更新组合框的值,但不知道如何获得选定的文本字体!我已经尝试了各种狡猾的解决方法 - 其中非工作$ / b>

任何帮助appriciated



Advance

Andy

解决方案

CaretListener 。在每个caretUpdate上使用代码

pre $ AttributeSet attrs =((StyleEditorKit)editorPane.getEditorKit())。getInputAttributes()
StyleConstants.getFontFamily(attrs);


Basically the question says it all;

I have a JEditiorPane with the content type 'text/html'. I have created a font family and font size combo box and enabled them using the StyledEditorKit actions. This works great and I can change the font attributes of selected text (you what it does...)

The only thing is when I select the text it's a bit confusing because the ComboBox's still show the users previous selection. I would love to implement the functionality to update the combo box values according the selected text but cannot figure out how to get the selected texts font! I've tried all sorts of crafty workarounds - non of which have worked

Any Help appriciated

Thanks In Advance

Andy

解决方案

Add a CaretListener. On each caretUpdate use the code

AttributeSet attrs=((StyleEditorKit)editorPane.getEditorKit()).getInputAttributes()
StyleConstants.getFontFamily(attrs);

这篇关于获取JEditorPane中选定文本的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆