本文整理了Java中javax.swing.JTextArea.getFontMetrics()
方法的一些代码示例,展示了JTextArea.getFontMetrics()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextArea.getFontMetrics()
方法的具体详情如下:
包路径:javax.swing.JTextArea
类名称:JTextArea
方法名:getFontMetrics
暂无
代码示例来源:origin: JetBrains/ideavim
private void positionPanel() {
final JComponent contentComponent = myEditor.getContentComponent();
Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, contentComponent);
setSize(scroll.getSize());
myLineHeight = myText.getFontMetrics(myText.getFont()).getHeight();
int count = countLines(myText.getText());
int visLines = getSize().height / myLineHeight - 1;
int lines = Math.min(count, visLines);
setSize(getSize().width, lines * myLineHeight + myLabel.getPreferredSize().height +
getBorder().getBorderInsets(this).top * 2);
int height = getSize().height;
Rectangle bounds = scroll.getBounds();
bounds.translate(0, scroll.getHeight() - height);
bounds.height = height;
Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(),
SwingUtilities.getRootPane(contentComponent).getGlassPane());
bounds.setLocation(pos);
setBounds(bounds);
myScrollPane.getVerticalScrollBar().setValue(0);
if (!Options.getInstance().isSet("more")) {
// FIX
scrollOffset(100000);
}
else {
scrollOffset(0);
}
}
代码示例来源:origin: RaiMan/SikuliX2
int w = width * ta.getFontMetrics(ta.getFont()).charWidth('m');
int h = (int) (lines * ta.getFontMetrics(ta.getFont()).getHeight());
ta.setPreferredSize(new Dimension(w, h));
ta.setMaximumSize(new Dimension(w, 2 * h));
代码示例来源:origin: bcdev/beam
private static int countLines(JTextArea component, String value, int max) {
int lineCount = 0;
FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
for (String s : value.split("\n")) {
lineCount += 1 + fontMetrics.stringWidth(s) / max;
}
return lineCount;
}
}
代码示例来源:origin: senbox-org/snap-desktop
private static int countLines(JTextArea component, String value, int max) {
int lineCount = 0;
FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
for (String s : value.split("\n")) {
lineCount += 1 + fontMetrics.stringWidth(s) / max;
}
return lineCount;
}
}
代码示例来源:origin: net.java.dev.swing-layout/swing-layout
private int getTextAreaBaseline(JTextArea text, int height) {
Insets insets = text.getInsets();
FontMetrics fm = text.getFontMetrics(text.getFont());
return insets.top + fm.getAscent();
}
代码示例来源:origin: net.java.dev.swing-layout/swing-layout
private static int getTextAreaBaseline(JTextArea text, int height) {
Insets insets = text.getInsets();
FontMetrics fm = text.getFontMetrics(text.getFont());
return insets.top + fm.getAscent();
}
代码示例来源:origin: jpcsp/jpcsp
public void RefreshMemory() {
int addr = startaddress;
taMemoryView.setText("");
visiblelines = taMemoryView.getHeight() / taMemoryView.getFontMetrics(taMemoryView.getFont()).getHeight();
for (int y = 0; y < visiblelines; y++) {
if (y > 0) {
taMemoryView.append("\n");
}
taMemoryView.append(getMemoryView(addr));
addr += 16;
}
}
代码示例来源:origin: net.java.openjdk.cacio/cacio-shared
@Override
public Dimension getPreferredSize(int rows, int columns) {
Font f = textArea.getFont();
FontMetrics fm = textArea.getFontMetrics(f);
int w = fm.charWidth('m') * columns;
int h = fm.getHeight() * rows;
Dimension spSize = getSwingComponent().getMinimumSize();
spSize.width += w;
spSize.height += h;
return spSize;
}
代码示例来源:origin: com.sikulix/sikulixapi
int w = (width + pluswidth) * ta.getFontMetrics(ta.getFont()).charWidth('m');
int h = (lines + 1) * ta.getFontMetrics(ta.getFont()).getHeight();
ta.setText(text);
ta.setLineWrap(true);
代码示例来源:origin: net.java.dev.appframework/appframework
final JTextArea textArea = new JTextArea((String)message);
textArea.setFont(font);
int lh = textArea.getFontMetrics(font).getHeight();
Insets margin = new Insets(0, 0, lh, 24); // top left bottom right
textArea.setMargin(margin);
代码示例来源:origin: stackoverflow.com
public String formatText(JTextArea textArea)
{
StringBuilder text = new StringBuilder( textArea.getText() );
int lineHeight = textArea.getFontMetrics( textArea.getFont() ).getHeight();
Point view = new Point(textArea.getWidth(), textArea.getInsets().top);
int length = textArea.getDocument().getLength();
int endOfLine = textArea.viewToModel(view);
int lines = 0;
while (endOfLine < length)
{
int adjustedEndOfLine = endOfLine + lines;
if (text.charAt(adjustedEndOfLine) == ' ')
{
text.insert(adjustedEndOfLine + 1, '\n');
lines++;
}
view.y += lineHeight;
endOfLine = textArea.viewToModel(view);
}
return text.toString();
}
代码示例来源:origin: org.jdesktop.bsaf/bsaf
final JTextArea textArea = new JTextArea((String) message);
textArea.setFont(font);
int lh = textArea.getFontMetrics(font).getHeight();
Insets margin = new Insets(0, 0, lh, 24); // top left bottom right
textArea.setMargin(margin);
代码示例来源:origin: net.sf.ingenias/editor
int length = jta.getFontMetrics(GraphConstants.getFont(this.
getAllAttributes())).stringWidth(text) + 10;
int height = jta.getFontMetrics(GraphConstants.getFont(this.
getAllAttributes())).getHeight();
jta.setSize(length, height + 5);
代码示例来源:origin: stackoverflow.com
private static int countLines(JTextArea textArea)
{
AttributedString text = new AttributedString(textArea.getText());
text.addAttribute(TextAttribute.FONT, textArea.getFont());
FontRenderContext frc = textArea.getFontMetrics(textArea.getFont()).getFontRenderContext();
AttributedCharacterIterator charIt = text.getIterator();
LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(charIt, frc);
Insets textAreaInsets = textArea.getInsets();
float formatWidth = textArea.getWidth() - textAreaInsets.left - textAreaInsets.right;
lineMeasurer.setPosition(charIt.getBeginIndex());
int noLines = 0;
while (lineMeasurer.getPosition() < charIt.getEndIndex())
{
lineMeasurer.nextLayout(formatWidth);
noLines++;
}
return noLines;
}
内容来源于网络,如有侵权,请联系作者删除!