Java Code Examples for javax.swing.JTable#getFont()

The following examples show how to use javax.swing.JTable#getFont() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatTableModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
	int row, int column)
{
	Font tableFont = table.getFont();
	if (column < 3)
	{
		setFont(FontManipulation.bold(tableFont));
	}
	else
	{
		setFont(FontManipulation.plain(tableFont));
	}
	setBackground(table.getBackground());
	setForeground(table.getForeground());
	Integer mod = (Integer) value;
	if (mod == 0 && column > 3)
	{
		// let's use a pretty em dash instead of hyphen/minus.
		setText("\u2014");
	}
	else
	{
		setText(formatter.format(mod.longValue()));
	}
	return this;
}
 
Example 2
Source File: ObdItemTableRenderer.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
/**
 * set visualisation parameters referring to given table
 *
 * @param table
 *          - the table object to refer to ...
 */
private void setParentTable(JTable table)
{
	parentTable = table;
	// set the font only once, and then just use it
	parentFont = table.getFont();
	setFont(parentFont);

	// get background color from Table
	bgColor = table.getBackground();
	// get selection color from Table
	selColor = table.getSelectionBackground();
}
 
Example 3
Source File: StatTableModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
	int row, int column)
{
	Font tableFont = table.getFont();
	if (column < 3)
	{
		setFont(FontManipulation.bold(tableFont));
	}
	else
	{
		setFont(FontManipulation.plain(tableFont));
	}
	setBackground(table.getBackground());
	setForeground(table.getForeground());
	Integer mod = (Integer) value;
	if (mod == 0 && column > 3)
	{
		// let's use a pretty em dash instead of hyphen/minus.
		setText("\u2014");
	}
	else
	{
		setText(formatter.format(mod.longValue()));
	}
	return this;
}
 
Example 4
Source File: RegistrationExplorerPanel.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public void initComponent( final ViewRegistrations viewRegistrations )
{
	tableModel = new RegistrationTableModel( viewRegistrations, this );

	table = new JTable();
	table.setModel( tableModel );
	table.setSurrendersFocusOnKeystroke( true );
	table.setSelectionMode( ListSelectionModel.SINGLE_INTERVAL_SELECTION );
	
	final DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
	centerRenderer.setHorizontalAlignment( JLabel.CENTER );
	
	// center all columns
	for ( int column = 0; column < tableModel.getColumnCount(); ++column )
		table.getColumnModel().getColumn( column ).setCellRenderer( centerRenderer );

	table.setPreferredScrollableViewportSize( new Dimension( 1020, 300 ) );
	table.getColumnModel().getColumn( 0 ).setPreferredWidth( 300 );
	for ( int i = 1; i < table.getColumnCount(); ++i )
		table.getColumnModel().getColumn( i ).setPreferredWidth( 100 );
	final Font f = table.getFont();
	
	table.setFont( new Font( f.getName(), f.getStyle(), 11 ) );
	
	this.setLayout( new BorderLayout() );
	this.label = new JLabel( "View Description --- " );
	this.add( label, BorderLayout.NORTH );
	this.add( new JScrollPane( table ), BorderLayout.CENTER );
	
	addPopupMenu( table );
}
 
Example 5
Source File: DiagnosticsForThreads.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
public DiagnosticsForThreads() {

    JTable table = new JTable(tableModel);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

    // code added Feb 2014 by Doug Brown
  	FontSizer.setFonts(table, FontSizer.getLevel());
  	Font font = table.getFont();
  	table.setRowHeight(font.getSize()+4);
  	table.getTableHeader().setFont(font);
    // end added code

    TableColumnModel colModel = table.getColumnModel();
    int numColumns = colModel.getColumnCount();

    for (int i = 0; i < numColumns - 1; i++) {
      TableColumn col = colModel.getColumn(i);

      col.sizeWidthToFit();
      col.setPreferredWidth(col.getWidth() + 5);
      col.setMaxWidth(col.getWidth() + 5);
    }

    JScrollPane sp = new JScrollPane(table);

    setLayout(new BorderLayout());
    add(sp, BorderLayout.CENTER);
  }
 
Example 6
Source File: FormattedCellRenderer.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JPanel newPanel = new JPanel();
  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newPanel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");

    /*
     * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
     * otherwise setBorder() may throw a NullPointerException
     */
    if ((border != null) && (border.getBorderInsets(newPanel) != null)) {
      newPanel.setBorder(border);
    }

  }

  if (value != null) {

    String text;

    if (value instanceof Number)
      text = format.format((Number) value);
    else
      text = value.toString();

    JLabel newLabel = new JLabel(text, JLabel.CENTER);

    if (font != null)
      newLabel.setFont(font);
    else if (table.getFont() != null)
      newLabel.setFont(table.getFont());

    newPanel.add(newLabel);

  }

  return newPanel;

}
 
Example 7
Source File: SwingHelper.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
public static void scaleTableRowHeight(JTable table) {
    if (table != null && table.getFont() != null) {
        table.setRowHeight(table.getFontMetrics(table.getFont()).getHeight() + JBUI.scale(1));
    }
}
 
Example 8
Source File: FormattedCellRenderer.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JPanel newPanel = new JPanel();
  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newPanel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");

    /*
     * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
     * otherwise setBorder() may throw a NullPointerException
     */
    if ((border != null) && (border.getBorderInsets(newPanel) != null)) {
      newPanel.setBorder(border);
    }

  }

  if (value != null) {

    String text;

    if (value instanceof Number)
      text = format.format((Number) value);
    else
      text = value.toString();

    JLabel newLabel = new JLabel(text, JLabel.CENTER);

    if (font != null)
      newLabel.setFont(font);
    else if (table.getFont() != null)
      newLabel.setFont(table.getFont());

    newPanel.add(newLabel);

  }

  return newPanel;

}
 
Example 9
Source File: ComponentCellRenderer.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JPanel newPanel = new JPanel();
  newPanel.setLayout(new OverlayLayout(newPanel));

  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newPanel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");
    if (border != null)
      newPanel.setBorder(border);
  }

  if (value != null) {

    if (value instanceof JComponent) {

      newPanel.add((JComponent) value);

    } else {

      JLabel newLabel = new JLabel();
      if (value instanceof IIsotope) {
        IIsotope is = (IIsotope) value;
        newLabel.setText(is.getSymbol());
      } else {
        newLabel.setText(value.toString());
      }

      if (font != null)
        newLabel.setFont(font);
      else if (table.getFont() != null)
        newLabel.setFont(table.getFont());

      newPanel.add(newLabel);
    }

    if (createTooltips)
      newPanel.setToolTipText(value.toString());

  }

  return newPanel;

}