List of usage examples for java.awt FontMetrics getAscent
public int getAscent()
From source file:BasicDraw.java
public void paint(Graphics g) { Font font = new Font("Serif", Font.PLAIN, 12); g.setFont(font);/*w ww . j a v a 2s.co m*/ g.drawString("a String", 10, 10); FontMetrics fontMetrics = g.getFontMetrics(); g.drawString("aString", 10, 10 + fontMetrics.getAscent()); }
From source file:CenterTextRectangle.java
public void drawCenteredString(String s, int w, int h, Graphics g) { FontMetrics fm = g.getFontMetrics(); int x = (w - fm.stringWidth(s)) / 2; int y = (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent())) / 2); g.drawString(s, x, y);/*from w ww. ja va 2 s .c om*/ }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); FontMetrics fm = g.getFontMetrics(font); wordWidth = fm.stringWidth(word);//ww w.ja v a 2s. co m wordHeight = fm.getAscent(); g.setFont(new Font("impact", Font.PLAIN, 28)); g.setColor(Color.BLUE); g.drawString(word, x, y); }
From source file:Main.java
public void paint(Graphics g) { g.setFont(new Font("SansSerif", Font.BOLD, 12)); FontMetrics fm = g.getFontMetrics(); g.drawString("Current font: " + g.getFont(), 10, 40); g.drawString("Ascent: " + fm.getAscent(), 10, 55); g.drawString("Descent: " + fm.getDescent(), 10, 70); g.drawString("Height: " + fm.getHeight(), 10, 85); g.drawString("Leading: " + fm.getLeading(), 10, 100); Font font = new Font("Serif", Font.ITALIC, 14); fm = g.getFontMetrics(font);/*from w w w .ja v a 2 s . c om*/ g.setFont(font); g.drawString("Current font: " + font, 10, 130); g.drawString("Ascent: " + fm.getAscent(), 10, 145); g.drawString("Descent: " + fm.getDescent(), 10, 160); g.drawString("Height: " + fm.getHeight(), 10, 175); g.drawString("Leading: " + fm.getLeading(), 10, 190); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); String text = getWidth() + "x" + getHeight(); FontMetrics fm = g2d.getFontMetrics(); int x = (getWidth() - fm.stringWidth(text)) / 2; int y = ((getHeight() - fm.getHeight()) / 2) + fm.getAscent(); g2d.drawString(text, x, y);//from w w w . ja v a 2 s. c o m g2d.dispose(); }
From source file:DialogSeparator.java
public void paint(Graphics g) { g.setColor(getBackground());/* www . j a v a 2s .co m*/ g.fillRect(0, 0, getWidth(), getHeight()); Dimension d = getSize(); int y = (d.height - 3) / 2; g.setColor(Color.white); g.drawLine(1, y, d.width - 1, y); y++; g.drawLine(0, y, 1, y); g.setColor(Color.gray); g.drawLine(d.width - 1, y, d.width, y); y++; g.drawLine(1, y, d.width - 1, y); String text = getText(); if (text.length() == 0) return; g.setFont(getFont()); FontMetrics fm = g.getFontMetrics(); y = (d.height + fm.getAscent()) / 2; int fontWidth = fm.stringWidth(text); g.setColor(getBackground()); g.fillRect(OFFSET - 5, 0, OFFSET + fontWidth, d.height); g.setColor(getForeground()); g.drawString(text, OFFSET, y); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED);/*from w w w. ja v a 2s . c o m*/ g2d.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight()); g2d.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2); Font font = new Font("Arial", Font.BOLD, 48); g2d.setFont(font); FontMetrics fm = g2d.getFontMetrics(); int x = ((getWidth() - fm.stringWidth(text)) / 2); int y = ((getHeight() - fm.getHeight()) / 2) + fm.getAscent(); g2d.setColor(Color.BLACK); g2d.drawString(text, x, y); g2d.dispose(); }
From source file:MyCanvas.java
public void paintComponent(Graphics g) { super.paintComponent(g); // draw entire component white g.setColor(Color.white);/*from w w w . ja va 2 s . c o m*/ g.fillRect(0, 0, getWidth(), getHeight()); // yellow circle g.setColor(Color.yellow); g.fillOval(0, 0, 240, 240); // magenta circle g.setColor(Color.magenta); g.fillOval(160, 160, 240, 240); // paint the icon below blue sqaure int w = java2sLogo.getIconWidth(); int h = java2sLogo.getIconHeight(); java2sLogo.paintIcon(this, g, 280 - (w / 2), 120 - (h / 2)); // paint the icon below red sqaure java2sLogo.paintIcon(this, g, 120 - (w / 2), 280 - (h / 2)); // transparent red square g.setColor(m_tRed); g.fillRect(60, 220, 120, 120); // transparent green circle g.setColor(m_tGreen); g.fillOval(140, 140, 120, 120); // transparent blue square g.setColor(m_tBlue); g.fillRect(220, 60, 120, 120); g.setColor(Color.black); g.setFont(monoFont); FontMetrics fm = g.getFontMetrics(); w = fm.stringWidth("Java Source"); h = fm.getAscent(); g.drawString("Java Source", 120 - (w / 2), 120 + (h / 4)); g.setFont(sanSerifFont); fm = g.getFontMetrics(); w = fm.stringWidth("and"); h = fm.getAscent(); g.drawString("and", 200 - (w / 2), 200 + (h / 4)); g.setFont(serifFont); fm = g.getFontMetrics(); w = fm.stringWidth("Support."); h = fm.getAscent(); g.drawString("Support.", 280 - (w / 2), 280 + (h / 4)); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFNmTokenColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from w ww . ja va2 s . c o m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); g.drawString(firstLine, 4, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v2_1.CFLib.Swing.CFReferenceColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from w w w. j a v a 2 s. co m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof ICFLibAnyObj) { ICFLibAnyObj anyObj = (ICFLibAnyObj) value; str = anyObj.getObjQualifiedName(); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); g.drawString(firstLine, 4, leading + ascent + 4); } }