List of usage examples for java.awt FontMetrics getHeight
public int getHeight()
From source file:Main.java
License:asdf
public Dimension getPreferredSize(JComponent c) { FontMetrics metrics = c.getFontMetrics(c.getFont()); String tipText = ((JToolTip) c).getTipText(); if (tipText == null) { tipText = ""; }/* w w w. j av a 2 s . com*/ Image image = new ImageIcon("yourImage").getImage(); int width = SwingUtilities.computeStringWidth(metrics, tipText); int height = metrics.getHeight() + image.getHeight(c); if (width < image.getWidth(c)) { width = image.getWidth(c); } return new Dimension(width, height); }
From source file:metrics.java
License:asdf
public void paint(Graphics g) { g.translate(100, 100);// w ww . j a v a 2 s . com FontMetrics fm = null; int ascent, descent, leading, width1, width2, height; String string1 = "dsdas"; String string2 = "asdf"; int xPos = 25, yPos = 50; fm = g.getFontMetrics(); ascent = fm.getAscent(); descent = fm.getDescent(); leading = fm.getLeading(); height = fm.getHeight(); width1 = fm.stringWidth(string1); width2 = fm.stringWidth(string2); g.drawString(string1, xPos, yPos); g.drawLine(xPos, yPos - ascent - leading, xPos + width1, yPos - ascent - leading); g.drawLine(xPos, yPos - ascent, xPos + width1, yPos - ascent); g.drawLine(xPos, yPos, xPos + width1, yPos); g.drawLine(xPos, yPos + descent, xPos + width1, yPos + descent); g.drawString(string2, xPos, yPos + height); g.drawLine(xPos, yPos - ascent - leading + height, xPos + width2, yPos - ascent - leading + height); g.drawLine(xPos, yPos - ascent + height, xPos + width2, yPos - ascent + height); g.drawLine(xPos, yPos + height, xPos + width2, yPos + height); g.drawLine(xPos, yPos + descent + height, xPos + width2, yPos + descent + height); }
From source file:Main.java
public void paint(Graphics g) { g.translate(100, 100);// w w w . jav a 2 s. c o m FontMetrics fm = null; int ascent, descent, leading, width1, width2, height; String string1 = "www.java2s.com"; String string2 = "java2s.com"; int xPos = 25, yPos = 50; fm = g.getFontMetrics(); ascent = fm.getAscent(); descent = fm.getDescent(); leading = fm.getLeading(); height = fm.getHeight(); width1 = fm.stringWidth(string1); width2 = fm.stringWidth(string2); g.drawString(string1, xPos, yPos); g.drawLine(xPos, yPos - ascent - leading, xPos + width1, yPos - ascent - leading); g.drawLine(xPos, yPos - ascent, xPos + width1, yPos - ascent); g.drawLine(xPos, yPos, xPos + width1, yPos); g.drawLine(xPos, yPos + descent, xPos + width1, yPos + descent); g.drawString(string2, xPos, yPos + height); g.drawLine(xPos, yPos - ascent - leading + height, xPos + width2, yPos - ascent - leading + height); g.drawLine(xPos, yPos - ascent + height, xPos + width2, yPos - ascent + height); g.drawLine(xPos, yPos + height, xPos + width2, yPos + height); g.drawLine(xPos, yPos + descent + height, xPos + width2, yPos + descent + height); }
From source file:com.callidusrobotics.swing.SwingConsole.java
private void initConsole(final Font font, final int rows, final int cols) { frame = new JFrame(); icon = new ImageIcon(); label = new JLabel(icon); // Compute font metrics final DisplayMode displayMode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDisplayMode();/* w ww . j av a2 s . com*/ frame.setVisible(true); imageBuffer = frame.createImage(displayMode.getWidth(), displayMode.getHeight()); graphicsRenderer = imageBuffer.getGraphics(); graphicsRenderer.setFont(font); final FontMetrics fontMetrics = graphicsRenderer.getFontMetrics(font); charHeight = fontMetrics.getHeight(); charWidth = fontMetrics.getHeight(); charHOffset = 0; charVOffset = fontMetrics.getAscent(); // Compute console dimensions and initialize graphics renderer final int width = charWidth * cols; final int height = charHeight * rows; imageBuffer = frame.createImage(width, height); graphicsRenderer = imageBuffer.getGraphics(); graphicsRenderer.setFont(font); render(); label.setBackground(TrueColor.MAGENTA); label.setBounds(0, 0, width, height); label.setVisible(true); frame.setBounds(0, 0, width, height); frame.setBackground(TrueColor.MAGENTA); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(label); frame.setCursor(null); frame.pack(); frame.setLocationRelativeTo(null); frame.setResizable(false); frame.addKeyListener(this); }
From source file:edu.csudh.goTorosBank.WithdrawServlet.java
public String writeIntoCheck(String filePath, String username, String theAmount, String amountInWords, String dateWrote, String person_payingto, String billType) throws IOException, NullPointerException { File blueCheck = new File("blank-blue-check.jpg"); String pathToOriginal = getServletContext().getRealPath("/" + blueCheck); File file = new File(pathToOriginal); BufferedImage imageToCopy = null; try {//w ww . j a v a2 s. c om imageToCopy = ImageIO.read(file); } catch (IOException e) { e.printStackTrace(); } String amount = theAmount; String person_gettingPayed = person_payingto; String amountinWords = amountInWords; String date = dateWrote; String bill_type = billType; int w = imageToCopy.getWidth(); int h = imageToCopy.getHeight(); BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = img.createGraphics(); g2d.setColor(g2d.getBackground()); g2d.fillRect(0, 0, w, h); g2d.drawImage(imageToCopy, 0, -100, null); g2d.setPaint(Color.black); g2d.setFont(new java.awt.Font("Serif", Font.BOLD, 36)); //g2d.setFont(new Font("Serif", Font.BOLD, 36)); FontMetrics fm = g2d.getFontMetrics(); int x = img.getWidth() - fm.stringWidth(amount) - 100; int y = fm.getHeight(); g2d.drawString(amount, x - 70, y + 335); g2d.drawString(person_gettingPayed, x - 800, y + 329); g2d.drawString(amountinWords, x - 940, y + 390); g2d.drawString(date, x - 340, y + 245); g2d.drawString(bill_type, x - 900, y + 530); String signature = "Use The Force"; g2d.setFont(new java.awt.Font("Monotype Corsiva", Font.BOLD | Font.ITALIC, 36)); g2d.drawString(signature, x - 340, y + 530); g2d.dispose(); /*write check to file*/ String filename = fileNameGenerator(username); String fullname = filePath + "_" + filename + ".jpg"; ImageIO.write(img, "jpg", new File(fullname)); return fullname; }
From source file:com.cburch.logisim.gui.start.AboutCredits.java
@Override protected void paintComponent(Graphics g) { FontMetrics[] fms = new FontMetrics[font.length]; for (int i = 0; i < fms.length; i++) { fms[i] = g.getFontMetrics(font[i]); }//from w w w. ja va 2s .com if (linesHeight == 0) { int y = 0; int index = -1; for (CreditsLine line : lines) { index++; if (index == initialLines) initialHeight = y; if (line.type == 0) y += 10; FontMetrics fm = fms[line.type]; line.y = y + fm.getAscent(); y += fm.getHeight(); } linesHeight = y; } Paint[] paint = paintSteady; int yPos = 0; int height = getHeight(); int initY = Math.min(0, initialHeight - height + About.IMAGE_BORDER); int maxY = linesHeight - height - initY; int totalMillis = 2 * MILLIS_FREEZE + (linesHeight + height) * MILLIS_PER_PIXEL; int offs = scroll % totalMillis; if (offs >= 0 && offs < MILLIS_FREEZE) { // frozen before starting the credits scroll int a = 255 * (MILLIS_FREEZE - offs) / MILLIS_FREEZE; if (a > 245) { paint = null; } else if (a < 15) { paint = paintSteady; } else { paint = new Paint[colorBase.length]; for (int i = 0; i < paint.length; i++) { Color hue = colorBase[i]; paint[i] = new GradientPaint(0.0f, 0.0f, derive(hue, a), 0.0f, fadeStop, hue); } } yPos = initY; } else if (offs < MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) { // scrolling through credits yPos = initY + (offs - MILLIS_FREEZE) / MILLIS_PER_PIXEL; } else if (offs < 2 * MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) { // freezing at bottom of scroll yPos = initY + maxY; } else if (offs < 2 * MILLIS_FREEZE + (linesHeight - initY) * MILLIS_PER_PIXEL) { // scrolling bottom off screen yPos = initY + (offs - 2 * MILLIS_FREEZE) / MILLIS_PER_PIXEL; } else { // scrolling next credits onto screen int millis = offs - 2 * MILLIS_FREEZE - (linesHeight - initY) * MILLIS_PER_PIXEL; paint = null; yPos = -height + millis / MILLIS_PER_PIXEL; } int width = getWidth(); int centerX = width / 2; maxY = getHeight(); for (CreditsLine line : lines) { int y = line.y - yPos; if (y < -100 || y > maxY + 50) continue; int type = line.type; if (paint == null) { g.setColor(colorBase[type]); } else { ((Graphics2D) g).setPaint(paint[type]); } g.setFont(font[type]); int textWidth = fms[type].stringWidth(line.text); g.drawString(line.text, centerX - textWidth / 2, line.y - yPos); Image img = line.img; if (img != null) { int x = width - line.imgWidth - About.IMAGE_BORDER; int top = y - fms[type].getAscent(); g.drawImage(img, x, top, this); } } }
From source file:org.zaproxy.zap.extension.callgraph.CallGraphFrame.java
public Dimension getTextDimension(String text, FontMetrics metrics) { int hgt = metrics.getHeight(); int adv = metrics.stringWidth(text); Dimension size = new Dimension(adv + 5, hgt + 5); return size;/*from ww w.j ava 2s . c o m*/ }
From source file:net.rptools.maptool.client.ui.ChatTypingNotification.java
/** * This component is only made visible when there are notifications to be displayed. That means the first couple of * IF statements in this method are redundant since paintComponent() will not be called unless the component is * visible, and it will only be visible when there are notifications... *///from w ww . ja v a 2s.c o m @Override protected void paintComponent(Graphics g) { // System.out.println("Chat panel is painting itself..."); if (AppPreferences.getTypingNotificationDuration() == 0) { return; } LinkedMap chatTypers = MapTool.getFrame().getChatNotificationTimers().getChatTypers(); if (chatTypers == null || chatTypers.isEmpty()) { return; } Boolean showBackground = AppPreferences.getChatNotificationShowBackground(); Graphics2D statsG = (Graphics2D) g.create(); Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD); Font font = AppStyle.labelFont; FontMetrics valueFM = g.getFontMetrics(font); FontMetrics keyFM = g.getFontMetrics(boldFont); int PADDING7 = 7; int PADDING3 = 3; int PADDING2 = 2; BufferedImage img = AppStyle.panelTexture; int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight()); setBorder(null); int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin(); int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin(); statsG.setFont(font); SwingUtil.useAntiAliasing(statsG); Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(), height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width, getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin() + PADDING2); int y = bounds.y + rowHeight; rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight()); setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight)) + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin())); if (showBackground) { g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this); AppStyle.miniMapBorder.paintAround(statsG, bounds); } Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7, AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(), AppStyle.chatImage.getHeight()); Set<?> keySet = chatTypers.keySet(); @SuppressWarnings("unchecked") Set<String> playerTimers = (Set<String>) keySet; for (String playerNamer : playerTimers) { if (showBackground) { statsG.setColor(new Color(249, 241, 230, 140)); statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); statsG.setColor(new Color(175, 163, 149)); statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(), (bounds.width - PADDING7 / 2) - PADDING3, rowHeight); } g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(), (int) rightRow.getHeight(), this); // Values statsG.setColor(MapTool.getFrame().getChatTypingLabelColor()); statsG.setFont(boldFont); statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer), bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5); y += PADDING2 + rowHeight; } if (showBackground) { AppStyle.shadowBorder.paintWithin(statsG, bounds); } else { setOpaque(false); } }
From source file:edu.ku.brc.ui.GradiantButton.java
@Override public Dimension getPreferredSize() { String text = getText();/*from www. j a v a 2 s .c o m*/ FontMetrics fm = this.getFontMetrics(getFont()); float scale = (50f / 40f) * this.getFont().getSize2D(); int w = fm.stringWidth(text); w += (int) (scale * 1.4f); int h = fm.getHeight(); h += (int) (scale * .3f); // Make sure the height is at least as big as the icon if (icon != null) { if (h <= icon.getIconHeight()) { h = icon.getIconHeight() + 4; } if (w <= icon.getIconWidth()) { w = icon.getIconWidth() + 2; } } return new Dimension(w, h); }
From source file:haven.Utils.java
public static int drawtext(Graphics g, String text, Coord c) { java.awt.FontMetrics m = g.getFontMetrics(); g.drawString(text, c.x, c.y + m.getAscent()); return (m.getHeight()); }