Search code examples
javafontssizejtextpanejtextcomponent

Font size in Jtextpane looks smaller then in other applications


I have JTextPane and if i write something into it with e.g. font size 12 then it looks smaller than text in e.g. MS Word with same size and same font family.

I've searched on the internet and I found that this is not just my specific problem. But I can't find any solution.

Set the bigger font size is not a solution for me.

enter image description here

Is it possible to change measure or something like that?


Solution

  • Actually there is DPI difference of java (72pixels per inch) and windows (96 pixels per inch). To reflect your fonts properly you can multiply them on the 96/72 on Windows.

    You can override

    public Font getFont(AttributeSet attr)
    

    method of DefaultStyledDocument where retrieve font size from the attribute set and increase it with the proportion.