简体   繁体   中英

Get font of selected text in JEditorPane

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM