GlyphVector v = f.createGlyphVector(getFontMetrics(f).getFontRenderContext(), "Hello"); s = v.getOutline(); setPreferredSize(new Dimension(300,300));
FontMetrics fontMetrics = getFontMetrics(BG_STRING_FONT); int w = fontMetrics.stringWidth(BACKGROUND_STRING); int h = fontMetrics.getHeight();
font1 = getFont(); font2 = font1.deriveFont(48f); fontRenderContext1 = getFontMetrics(font1).getFontRenderContext(); fontRenderContext2 = getFontMetrics(font2).getFontRenderContext(); MouseInputAdapter mouseHandler = new MouseInputAdapter() {
@Override public void setFont(Font font) { this.font = font; fontMetrics = component.getFontMetrics(font); }
@Override public FontMetrics getFontMetrics(Font font) { return component.getFontMetrics(font); }
private void initDefaults() { component = new JPanel(); stroke = new BasicStroke(); color = Color.black; font = new Font("Arial", Font.PLAIN, 12); fontMetrics = component.getFontMetrics(font); fontRenderContext = new FontRenderContext(null, true, false); translateX = 0; translateY = 0; }
private void updateSize(JComponent parent) { if (parent != null) { FontMetrics fmetrics = parent.getFontMetrics(parent.getFont()); iconHeight = fmetrics.getHeight() + 1; iconWidth = fmetrics.stringWidth(label) + 5; } }
/** * <p>Work out the </p> * Calculate the size of the Icon using the FontMetrics of the Font. */ private void calculateIconDimensions() { FontMetrics fm = component.getFontMetrics(font); iconWidth = fm.stringWidth(text); iconHeight = fm.getHeight(); component.revalidate(); }
private void update(JComponent component) { Font font = component.getFont(); FontMetrics fm = component.getFontMetrics(font); ascent = fm.getAscent(); descent = fm.getDescent(); height = fm.getHeight(); }
public static int getColumnWidthInPixels(String str, JComponent comp) { FontMetrics fm = comp.getFontMetrics(comp.getFont()); return fm.stringWidth(str); }
JComponent c = getSomeKindOfJComponent(); FontMetrics fm = c.getFontMetrics(c.getFont()); // or another font int strw = fm.stringWidth("My text");
JComponent c = ... // it can be label, button or any other component FontMetrics fm = c.getFontMetrics(c.getFont()); // or another font int strw = fm.stringWidth("My text");
@Override public Dimension getPreferredSize(JComponent c) { AbstractButton ab = (AbstractButton)c; FontMetrics fm = c.getFontMetrics(c.getFont()); return new Dimension(fm.stringWidth(ab.getText())+16,fm.getHeight()+8); }
/** * Return the minimum dimension for this visible bean. * @return a minimum bounding box for this bean. */ public Dimension getMinimumSize () { FontMetrics met; int width; int height; met = getFontMetrics (getFont ()); width = met.stringWidth ("http://localhost"); height = met.getLeading () + met.getHeight () + met.getDescent (); return (new Dimension (width, height)); }
/** * Return the minimum dimension for this visible bean. * @return a minimum bounding box for this bean. */ public Dimension getMinimumSize () { FontMetrics met; int width; int height; met = getFontMetrics (getFont ()); width = met.stringWidth ("Hello World"); height = met.getLeading () + met.getHeight () + met.getDescent (); return (new Dimension (width, height)); }
@Override public Dimension getPreferredSize(JComponent c) { final OnOffButton button = (OnOffButton)c; String text = button.getOffText().length() > button.getOnText().length() ? button.getOffText() : button.getOnText(); text = text.toUpperCase(); final FontMetrics fm = c.getFontMetrics(c.getFont()); int w = fm.stringWidth(text); int h = fm.getHeight(); h += 2*4; w += 3 * h / 2; return new Dimension(w, h); } @Override
/** Computes width of string up to maxCharCount, with font of given JComponent * and with maximum percentage of owning Window that can be taken */ private static int computeWidth (JComponent comp, int maxCharCount, int percent) { FontMetrics fm = comp.getFontMetrics(comp.getFont()); int charW = fm.charWidth('X'); int result = charW * maxCharCount; // limit width to 50% of containing window Window w = SwingUtilities.windowForComponent(comp); if (w != null) { result = Math.min(result, w.getWidth() * percent / 100); } return result; }
/** Computes width of string up to maxCharCount, with font of given JComponent * and with maximum percentage of owning Window that can be taken */ private static int computeWidth (JComponent comp, int maxCharCount, int percent) { FontMetrics fm = comp.getFontMetrics(comp.getFont()); int charW = fm.charWidth('X'); int result = charW * maxCharCount; // limit width to 50% of containing window Window w = SwingUtilities.windowForComponent(comp); if (w != null) { result = Math.min(result, w.getWidth() * percent / 100); } return result; }
private void setLabels() { FontMetrics fm = comp.getFontMetrics(FONT_LABEL); armorLabel = new PMSimpleLabel("Armor:", fm, Color.white); armorVLabel = new PMValueLabel(fm, Color.red.brighter()); avCritLabel = new PMSimpleLabel("Avionics:", fm, Color.white); //$NON-NLS-1$ engineCritLabel = new PMSimpleLabel("Engine:", fm, Color.white); //$NON-NLS-1$ fcsCritLabel = new PMSimpleLabel("FCS:", fm, Color.white); //$NON-NLS-1$ sensorCritLabel = new PMSimpleLabel("Sensors:", fm, Color.white); //$NON-NLS-1$ pilotCritLabel = new PMSimpleLabel("Pilot hits:", fm, Color.white); //$NON-NLS-1$ }
private void setLabels() { FontMetrics fm = comp.getFontMetrics(FONT_LABEL); for (int i = 0; i < max_size; i++) { nameLabel[i] = new PMSimpleLabel("Unknown", fm, Color.white); //$NON-NLS-1$ armorVLabel[i] = new PMValueLabel(fm, Color.red.brighter()); avCritLabel[i] = new PMSimpleLabel("Avionics:", fm, Color.white); //$NON-NLS-1$ engineCritLabel[i] = new PMSimpleLabel("Engine:", fm, Color.white); //$NON-NLS-1$ fcsCritLabel[i] = new PMSimpleLabel("FCS:", fm, Color.white); //$NON-NLS-1$ sensorCritLabel[i] = new PMSimpleLabel("Sensors:", fm, Color.white); //$NON-NLS-1$ pilotCritLabel[i] = new PMSimpleLabel("Pilot hits:", fm, Color.white); //$NON-NLS-1$ } }