javax.swing.JTable.getFont()方法的使用及代码示例

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

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

JTable.getFont介绍

暂无

代码示例

代码示例来源:origin: marytts/marytts

public static int getMaxColumnWidth(JTable table, int column) {
  // Set first to column header width as a minimum
  Font font = table.getFont();
  FontMetrics metrics = table.getGraphics().getFontMetrics(font);
  String header = table.getColumnName(column) + "   "; // Whitespace buffer as a crude way (hack)
                              // to account for the rendering context
  Test.output("Column name: " + header);
  // Convert from string length in characters to pixels
  int widest = metrics.stringWidth(header) + (2 * table.getColumnModel().getColumnMargin());
  Test.output("Starting widest value: " + header + " (" + widest + " pixels)");
  // Now go through each row to see if there is a longer value in the column
  int rows = table.getRowCount();
  Test.output("Row count: " + rows);
  for (int index = 0; index < rows; index++) {
    String cellValue = table.getValueAt(index, column).toString();
    int cellWidth = metrics.stringWidth(cellValue) + (2 * table.getColumnModel().getColumnMargin());
    if (cellWidth > widest) {
      widest = cellWidth;
      Test.output("New widest value: " + widest + " pixels");
    }
  }
  return widest;
}

代码示例来源:origin: neueda/jetbrains-plugin-graph-database-support

private int strWidth(String str) {
  return table.getFontMetrics(table.getFont())
      .charsWidth(str.toCharArray(), 0, str.length());
}

代码示例来源:origin: wildfly/wildfly

table.setFont(table.getFont().deriveFont(Font.BOLD));
add(new JScrollPane(table));

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

private int calculateColumnWidth(String txt) {
  Font font = getTargetList().getFont();
  FontMetrics fontMetrics = getTargetList().getFontMetrics(font);
  int width = fontMetrics.stringWidth(txt);
  return width;
}

代码示例来源:origin: de.dfki.mary/marytts-transcription

public void changeTableFont(String fontName) {
  int fontSize = table.getFont().getSize();
  System.out.println("prev: " + table.getFont().getName());
  table.setFont(new Font(fontName, Font.TRUETYPE_FONT, fontSize));
  System.out.println("next: " + fontName);
}

代码示例来源:origin: com.googlecode.clearnlp/clearnlp

public TRTablePane(TableModelListener listener, StringIntPair[] tags)
{
  setLayout(new BorderLayout());
  
  j_table = new JTable();
  j_table.setModel(new DefaultTableModel(new Object[][]{{0,"","",0,""}}, t_columns));
  j_table.getModel().addTableModelListener(listener);
  
  TableColumnModel columnModel = j_table.getColumnModel();
  
  for (StringIntPair tag : tags)
    setColumnEditor(columnModel, tag.s, tag.i);
  
  add(j_table.getTableHeader(), BorderLayout.NORTH);
  add(j_table, BorderLayout.CENTER);
  
  t_height = j_table.getFontMetrics(j_table.getFont()).getHeight();
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

protected void setValue(JTable table, Object value, int row, int column) {
    if (table != null) {
      setFont(table.getFont());
    }

    label.setText((value == null) ? "" : value.toString()); //NOI18N
  }
}

代码示例来源:origin: com.clearnlp/clearnlp

public TRTablePane(TableModelListener listener, StringIntPair[] tags)
{
  setLayout(new BorderLayout());
  
  j_table = new JTable();
  j_table.setModel(new DefaultTableModel(new Object[][]{{0,"","",0,""}}, t_columns));
  j_table.getModel().addTableModelListener(listener);
  
  TableColumnModel columnModel = j_table.getColumnModel();
  
  for (StringIntPair tag : tags)
    setColumnEditor(columnModel, tag.s, tag.i);
  
  add(j_table.getTableHeader(), BorderLayout.NORTH);
  add(j_table, BorderLayout.CENTER);
  
  t_height = j_table.getFontMetrics(j_table.getFont()).getHeight();
}

代码示例来源:origin: mustfun/mybatis-plus

@Override
  public Component getTableCellRendererComponent(JTable table, Object value,
                          boolean isSelected, boolean hasFocus, int row, int column) {
    JButton cmb = (JButton) value;
    cmb.setFont(table.getFont());
    if (isSelected){
    }
    return cmb;
  }
}

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

protected void setValue(JTable table, Object value, int row, int column) {
    if (table != null) {
      setFont(table.getFont());
    }

    if (value == null) {
      label.setText(""); // NOI18N
    } else {
      int index = ((Integer) value).intValue();
      label.setText(viewManager.getThreadName(index));
    }
  }
}

代码示例来源:origin: JDatePicker/JDatePicker

public void componentResized(ComponentEvent e) {
  // The new size of the table
  final double w = e.getComponent().getSize().getWidth();
  final double h = e.getComponent().getSize().getHeight();
  // Set the size of the font as a fraction of the width or the height, whichever is smallest
  final float sw = (float) Math.floor(w / 16);
  final float sh = (float) Math.floor(h / 8);
  dayTable.setFont(dayTable.getFont().deriveFont(Math.min(sw, sh)));
  // Set the row height as a fraction of the height
  final int r = (int) Math.floor(h / 6);
  dayTable.setRowHeight(r);
}

代码示例来源:origin: com.jtattoo/JTattoo

public void installDefaults() {
  super.installDefaults();
  // Setup the rowheight. The font may change if UI switches
  FontMetrics fm = JTattooUtilities.getFontMetrics(table, null, table.getFont());
  table.setRowHeight(fm.getHeight() + (fm.getHeight() / 4));
}

代码示例来源:origin: hneemann/Digital

private JTable createTable(ValueTable valueTable) {
  JTable table = new JTable(new ValueTableModel(valueTable));
  table.setDefaultRenderer(Value.class, new ValueRenderer());
  table.setDefaultRenderer(Integer.class, new NumberRenderer());
  final Font font = table.getFont();
  table.getColumnModel().getColumn(0).setMaxWidth(font.getSize() * 4);
  table.setRowHeight(font.getSize() * 6 / 5);
  return table;
}

代码示例来源:origin: hltfbk/Excitement-Open-Platform

@Override
  public void paint(Graphics g)
  {
    super.paint(g);
    setRowHeight(g.getFontMetrics(existingTreesTable.getFont()).getHeight());
  }
};

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

private static int getTableBaseline(JTable table, int height) {
  if (TABLE_LABEL == null) {
    TABLE_LABEL = new JLabel("");
    TABLE_LABEL.setBorder(new EmptyBorder(1, 1, 1, 1));
  }
  JLabel label = TABLE_LABEL;
  label.setFont(table.getFont());
  int rowMargin = table.getRowMargin();
  int baseline = getLabelBaseline(label, table.getRowHeight() -
                  rowMargin);
  return baseline += rowMargin / 2;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

protected void setValue(JTable table, Object value, int row, int column) {
  if (table != null) {
    setFont(table.getFont());
  }
  label.setText((value == null) ? "" : value.toString()); //NOI18N
}

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

private int getTableBaseline(JTable table, int height) {
  if (TABLE_LABEL == null) {
    TABLE_LABEL = new JLabel("");
    TABLE_LABEL.setBorder(new EmptyBorder(1, 1, 1, 1));
  }
  JLabel label = TABLE_LABEL;
  label.setFont(table.getFont());
  int rowMargin = table.getRowMargin();
  int baseline = getLabelBaseline(label, table.getRowHeight() -
                  rowMargin);
  return baseline += rowMargin / 2;
}

代码示例来源:origin: org.gephi/appearance-plugin-ui

public TextRenderer(String countMessage) {
  setFont(table.getFont());
  emptyIcon = new EmptyIcon();
  elementsMessage = countMessage;
}

代码示例来源:origin: tulskiy/musique

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  TableModel tableModel = table.getModel();
  if (tableModel instanceof MultiTagFieldModel) {
    if (((MultiTagFieldModel) tableModel).getTrackInfoItems().get(row).isMultiple()) {
      value = "";
    }
  }
  JTextField c = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
  c.setBorder(BorderFactory.createEmptyBorder());
  c.setFont(table.getFont());
  c.selectAll();
  return c;
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_http

@Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
      boolean hasFocus, int row, int column) {
    setText((String) value);
    setBackground(isSelected && !hasFocus ? table.getSelectionBackground() : table.getBackground());
    setForeground(isSelected && !hasFocus ? table.getSelectionForeground() : table.getForeground());
    setFont(table.getFont());
    return this;
  }
}

相关文章

JTable类方法