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

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

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

JScrollPane.getFontMetrics介绍

暂无

代码示例

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-notifications

private void updateTableColumnSizes() {
  ETable table = notificationTable;
  Font font = notificationScroll.getFont();
  FontMetrics fm = notificationScroll.getFontMetrics(font.deriveFont(Font.BOLD));
  int maxCharWidth = fm.charWidth('A'); // NOI18N
  int inset = 10;
  TableColumnModel columnModel = table.getColumnModel();
  TableColumn priorityColumn = columnModel.getColumn(0);
  String priorName = priorityColumn.getHeaderValue().toString();
  priorityColumn.setPreferredWidth(fm.stringWidth(priorName) + inset);
  TableColumn dateColumn = columnModel.getColumn(2);
  dateColumn.setPreferredWidth(15 * maxCharWidth + inset);
  TableColumn categoryColumn = columnModel.getColumn(3);
  categoryColumn.setPreferredWidth(7 * maxCharWidth + inset);
  TableColumn messageColumn = columnModel.getColumn(1);
  Border border = notificationScroll.getBorder();
  Insets insets;
  if (border != null) {
    insets = border.getBorderInsets(notificationScroll);
  } else {
    insets = new Insets(0, 0, 0, 0);
  }
  int remainingWidth = notificationScroll.getParent().getWidth() - insets.left - insets.right;
  remainingWidth -= 3 * columnModel.getColumnMargin();
  remainingWidth -= priorityColumn.getPreferredWidth();
  remainingWidth -= dateColumn.getPreferredWidth();
  remainingWidth -= categoryColumn.getPreferredWidth();
  messageColumn.setPreferredWidth(remainingWidth);
}

代码示例来源:origin: org.scijava/scijava-ui-swing

private synchronized void initGui() {
  setLayout(new MigLayout("inset 0", "[grow,fill]", "[grow,fill,align top]"));
  textPane = new JTextPane();
  textPane.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
  textPane.setEditable(false);
  doc = textPane.getStyledDocument();
  stdoutLocal = createStyle("stdoutLocal", null, Color.black, null, null);
  stderrLocal = createStyle("stderrLocal", null, Color.red, null, null);
  stdoutGlobal = createStyle("stdoutGlobal", stdoutLocal, null, null, true);
  stderrGlobal = createStyle("stderrGlobal", stderrLocal, null, null, true);
  // NB: We wrap the JTextPane in a JPanel to disable
  // the text pane's intelligent line wrapping behavior.
  // I.e.: we want console lines _not_ to wrap, but instead
  // for the scroll pane to show a horizontal scroll bar.
  // Thanks to: https://tips4java.wordpress.com/2009/01/25/no-wrap-text-pane/
  final JPanel textPanel = new JPanel();
  textPanel.setLayout(new BorderLayout());
  textPanel.add(textPane);
  scrollPane = new JScrollPane(textPanel);
  scrollPane.setPreferredSize(new Dimension(600, 600));
  // Make the scroll bars move at a reasonable pace.
  final FontMetrics fm = scrollPane.getFontMetrics(scrollPane.getFont());
  final int charWidth = fm.charWidth('a');
  final int lineHeight = fm.getHeight();
  scrollPane.getHorizontalScrollBar().setUnitIncrement(charWidth);
  scrollPane.getVerticalScrollBar().setUnitIncrement(2 * lineHeight);
  add(scrollPane);
}
// -- Helper methods --

代码示例来源:origin: net.sf.taverna.t2.ui-impl/contextual-views-impl

listScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
FontMetrics fm = listScroller.getFontMetrics(this.getFont());  
int listScrollerHeight = fm.getHeight()*(labelListModel.size()) + 75; //+75 just in case
listScroller.setPreferredSize(new Dimension(listScroller

相关文章

JScrollPane类方法