congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Graphics.getFont
Code IndexAdd Tabnine to your IDE (free)

How to use
getFont
method
in
java.awt.Graphics

Best Java code snippets using java.awt.Graphics.getFont (Showing top 20 results out of 2,223)

origin: stackoverflow.com

 public static void main(String[] args) throws Exception {
  final BufferedImage image = ImageIO.read(new URL(
    "http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png"));

  Graphics g = image.getGraphics();
  g.setFont(g.getFont().deriveFont(30f));
  g.drawString("Hello World!", 100, 100);
  g.dispose();

  ImageIO.write(image, "png", new File("test.png"));
}
origin: stackoverflow.com

 import java.awt.*;

public class TestComponent extends JPanel {

  private void drawString(Graphics g, String text, int x, int y) {
    for (String line : text.split("\n"))
      g.drawString(line, x, y += g.getFontMetrics().getHeight());
  }

  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    drawString(g, "hello\nworld", 20, 20);
    g.setFont(g.getFont().deriveFont(20f));
    drawString(g, "part1\npart2", 120, 120);
  }

  public static void main(String s[]) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new TestComponent());
    f.setSize(220, 220);
    f.setVisible(true);
  }
}
origin: stackoverflow.com

 public Font scaleFont(String text, Rectangle rect, Graphics g, Font pFont) {
  float fontSize = 20.0f;
  Font font = pFont;

  font = g.getFont().deriveFont(fontSize);
  int width = g.getFontMetrics(font).stringWidth(text);
  fontSize = (rect.width / width ) * fontSize;
  return g.getFont().deriveFont(fontSize);
}
origin: cybergarage/cybergarage-upnp

private Font getFont(Graphics g, int size)
{
  Font font = new Font(DEFAULT_FONT_NAME, Font.PLAIN, size);
  if (font != null)
    return font;
  return g.getFont();
}
  
origin: org.netbeans.api/org-openide-awt

if (strikethrough) {
  int stPos = Math.round(lm.getStrikethroughOffset()) +
    g.getFont().getBaselineFor(chars[pos]) + 1;
    g.getFont().getBaselineFor(chars[pos]) + 1;
origin: cybergarage/cybergarage-upnp

private Font getFont(Graphics g, int size)
{
  Font font = new Font(DEFAULT_FONT_NAME, Font.BOLD, size);
  if (font != null)
    return font;
  return g.getFont();
}
  
origin: net.sourceforge.ondex.apps/ovtk2

  public Point getToolTipLocation(MouseEvent e) {
    Graphics g = getGraphics();
    FontMetrics metrics = g.getFontMetrics(g.getFont());
    String prefix = itemnameHistory.size() <= 9 ? "8: " : "88: ";
    int prefixWidth = metrics.stringWidth(prefix);
    int x = JButton.TRAILING + JButton.LEADING - 1 + prefixWidth;
    return new Point(x, 0);
  }
}
origin: cybergarage/cybergarage-upnp

private Font getFont(Graphics g, int size)
{
  Font font = new Font(DEFAULT_FONT_NAME, Font.BOLD, size);
  if (font != null)
    return font;
  return g.getFont();
}
  
origin: ggp-org/ggp-base

public static void fillWithString(Graphics g, String theText, double sizeFactor) {
  int theHeight = g.getClipBounds().height;
  int theWidth = g.getClipBounds().width;
  Font theFont = g.getFont().deriveFont((float) (theHeight / sizeFactor)).deriveFont(Font.BOLD);
  g.setFont(theFont);
  FontMetrics theMetric = g.getFontMetrics();
  g.drawString(theText, (theWidth - theMetric.stringWidth(theText)) / 2, theMetric.getAscent() + (theHeight - (theMetric.getDescent() + theMetric.getAscent())) / 2);
}
origin: apache/felix

private Font getFont(Graphics g, int size)
{
  Font font = new Font(DEFAULT_FONT_NAME, Font.PLAIN, size);
  if (font != null)
    return font;
  return g.getFont();
}
  
origin: undera/jmeter-plugins

private void calculateYAxisDimensions(Graphics g) {
  FontMetrics fm = g.getFontMetrics(g.getFont());
  int axisWidth = getYLabelsMaxWidth(fm) + spacing * 3 + fm.getHeight();
  yAxisRect.setBounds(chartRect.x, chartRect.y, axisWidth, chartRect.height);
  if (!isPreview) {
    chartRect.setBounds(chartRect.x + axisWidth, chartRect.y, chartRect.width - axisWidth, chartRect.height);
  } else {
    chartRect.setBounds(chartRect.x + previewInset, chartRect.y, chartRect.width, chartRect.height);
  }
}
origin: cybergarage/cybergarage-upnp

private Font getFont(Graphics g, int size)
{
  Font font = new Font(DEFAULT_FONT_NAME, Font.BOLD, size);
  if (font != null)
    return font;
  return g.getFont();
}
  
origin: kg.apc/jmeter-plugins-cmn-jmeter

private void calculateYAxisDimensions(Graphics g) {
  FontMetrics fm = g.getFontMetrics(g.getFont());
  int axisWidth = getYLabelsMaxWidth(fm) + spacing * 3 + fm.getHeight();
  yAxisRect.setBounds(chartRect.x, chartRect.y, axisWidth, chartRect.height);
  if (!isPreview) {
    chartRect.setBounds(chartRect.x + axisWidth, chartRect.y, chartRect.width - axisWidth, chartRect.height);
  } else {
    chartRect.setBounds(chartRect.x + previewInset, chartRect.y, chartRect.width, chartRect.height);
  }
}
origin: apache/felix

private Font getFont(Graphics g, int size)
{
  Font font = new Font(DEFAULT_FONT_NAME, Font.BOLD, size);
  if (font != null)
    return font;
  return g.getFont();
}
  
origin: stackoverflow.com

private final Font getFont()
     {
       Graphics g = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB).getGraphics();
       Font font = new Font(g.getFont().toString(), 0, 12);
       g.dispose();
       return font;
     }
origin: org.databene/databene-commons

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
  if (background != null)
    background.paintIcon(c, g, x + backgroundXOffset, y + backgroundYOffset);
  g.setColor(color);
  Font origFont = g.getFont();
  g.setFont(font);
  g.drawString(text, x + textXOffset, y + textYOffset);
  g.setFont(origFont);
}
origin: net.sf.taverna.t2.ui-activities/component-activity-ui

  @Override
  public void paintBorder(java.awt.Component c, Graphics g, int x, int y,
      int width, int height) {
    g.setColor(COLOR);
    g.fillRect(x, y, width, 20);
    g.setFont(g.getFont().deriveFont(BOLD));
    g.setColor(WHITE);
    g.drawString(text, x + 5, y + 15);
  }
}
origin: com.googlecode.jinahya/ocap-api

  /**
   * Returns a <code>String</code> object representing this 
   *                        <code>DVBGraphics</code> object's value.
   * @return       a string representation of this graphics context.
   * @since MHP 1.0
   */
  public String toString() {    
  return getClass().getName() + "[font=" + getFont() + ",color=" + getColor() + "]";
  }
}
origin: UNIVALI-LITE/Portugol-Studio

private void criarBuffer()
{
  createBufferStrategy(2);
  buffer = getBufferStrategy();
  if (fonteTexto == null)
  {
    Graphics g = buffer.getDrawGraphics();
    fonteTexto = g.getFont();
    dimensoesFonte = getFontMetrics(fonteTexto);
    g.dispose();
  }
}
origin: net.java.abeille/abeille

public void init(DrawContext ctx) {
  JTextComponent c = ctx.getEditorUI().getComponent();
  gColor = graphics.getColor();
  gFont = graphics.getFont();
  // initialize reference to annotations
  annos = ctx.getEditorUI().getDocument().getAnnotations();
}
java.awtGraphicsgetFont

Javadoc

Gets the current font.

Popular methods of Graphics

  • setColor
  • drawImage
    Draws as much of the specified image as is currently available. The image is drawn with its top-left
  • fillRect
    Fills the specified rectangle. The left and right edges of the rectangle are atx and x + width - 1.
  • drawLine
    Draws a line, using the current color, between the points(x1, y1) and (x2, y2) in this graphics con
  • drawString
    Draws the text given by the specified iterator, using this graphics context's current color. The ite
  • dispose
    Disposes of this graphics context and releases any system resources that it is using. A Graphics obj
  • setFont
    Sets this graphics context's font to the specified font. All subsequent text operations using this g
  • drawRect
    Draws the outline of the specified rectangle. The left and right edges of the rectangle are atx and
  • getFontMetrics
  • create
    Creates a new Graphics object based on thisGraphics object, but with a new translation and clip area
  • getColor
    Gets this graphics context's current color.
  • translate
    Translates the origin of the graphics context to the point (x,y) in the current coordinate system. M
  • getColor,
  • translate,
  • getClipBounds,
  • setClip,
  • fillPolygon,
  • fillOval,
  • drawOval,
  • getClip,
  • drawRoundRect

Popular in Java

  • Making http post requests using okhttp
  • setScale (BigDecimal)
  • findViewById (Activity)
  • requestLocationUpdates (LocationManager)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Reference (javax.naming)
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now