Get font of selected text in JEditorPane

邮差的信 提交于 2019-12-24 18:30:25

问题


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


回答1:


Add a CaretListener. On each caretUpdate use the code

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


来源:https://stackoverflow.com/questions/5021662/get-font-of-selected-text-in-jeditorpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!