kuangshuai
3 years ago
4 changed files with 40 additions and 36 deletions
@ -0,0 +1,28 @@
|
||||
package com.fr.design.mainframe.guide.utils; |
||||
|
||||
import com.fr.base.GraphHelper; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JTextPane; |
||||
import javax.swing.text.MutableAttributeSet; |
||||
import javax.swing.text.SimpleAttributeSet; |
||||
import javax.swing.text.StyleConstants; |
||||
import java.awt.FontMetrics; |
||||
import java.awt.Insets; |
||||
|
||||
public class GuideUIUtils { |
||||
public static void setTextPaneLineHeight(JTextPane pane, int lineHeight) { |
||||
pane.selectAll(); |
||||
pane.setMargin(new Insets(0,0,0,0)); |
||||
MutableAttributeSet set = new SimpleAttributeSet(pane.getParagraphAttributes()); |
||||
FontMetrics fontMetrics = GraphHelper.getFontMetrics(pane.getFont()); |
||||
int delta = (lineHeight - fontMetrics.getHeight()) / 2 * 2 ; |
||||
if (delta > 0) { |
||||
StyleConstants.setLineSpacing(set, delta/ 2.0f / fontMetrics.getHeight()); |
||||
pane.setParagraphAttributes(set, false); |
||||
int dis = fontMetrics.getDescent() - fontMetrics.getLeading(); |
||||
int marginTop = dis > 0 ? ((delta - dis) / 2 + dis) : ((delta - dis) / 2); |
||||
pane.setBorder(BorderFactory.createEmptyBorder(marginTop, 0,0,0)); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue