javax.swing.JComboBox.getFontMetrics()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中javax.swing.JComboBox.getFontMetrics()方法的一些代码示例,展示了JComboBox.getFontMetrics()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComboBox.getFontMetrics()方法的具体详情如下:
包路径:javax.swing.JComboBox
类名称:JComboBox
方法名:getFontMetrics

JComboBox.getFontMetrics介绍

暂无

代码示例

代码示例来源:origin: org.ihtsdo/wb-api

public int getWidestItemWidth() {
    int numItems = comboBox.getItemCount();
    Font font = comboBox.getFont();
    FontMetrics metrics = comboBox.getFontMetrics(font);
    int widest = 0;
    for (int i = 0; i < numItems; i++) {
      Object item = comboBox.getItemAt(i);
      int lineWidth = metrics.stringWidth(item.toString());
      widest = Math.max(widest, lineWidth);
    }
    return widest;
  }
}

代码示例来源:origin: cytoscape/application

FontMetrics fm = box.getFontMetrics(scrollPane.getFont());
w = (int)fm.stringWidth(wsp.getWidest());
h = (int)scrollPane.getMinimumSize().getHeight();

代码示例来源:origin: GoldenGnu/jeveassets

FontMetrics fontMetrics = jComboBox.getFontMetrics(jComboBox.getFont());
EnumTableColumn<E>  longestColumn = null;
for (EnumTableColumn<E> column : allColumns) {

代码示例来源:origin: net.java.dev.swing-layout/swing-layout

FontMetrics fm = combobox.getFontMetrics(combobox.getFont());
return y + fm.getAscent();

代码示例来源:origin: net.java.dev.swing-layout/swing-layout

private int getComboBoxBaseline(JComboBox combobox, int height) {
  Insets insets = combobox.getInsets();
  int y = insets.top;
  height -= (insets.top + insets.bottom);
  if (combobox.isEditable()) {
    ComboBoxEditor editor = combobox.getEditor();
    if (editor != null && (editor.getEditorComponent() instanceof
                JTextField)) {
      JTextField tf = (JTextField)editor.getEditorComponent();
      return y + getSingleLineTextBaseline(tf, height);
    }
  }
  y -= 1;
  // Use the renderer to calculate baseline
  ListCellRenderer renderer = combobox.getRenderer();
  if (renderer instanceof JLabel) {
    return y + getLabelBaseline((JLabel)renderer, height);
  }
  // Renderer isn't a label, use metrics directly.
  FontMetrics fm = combobox.getFontMetrics(combobox.getFont());
  return y + fm.getAscent();
}

相关文章

JComboBox类方法