Refine search
Font labelFont = label.getFont(); String labelText = label.getText(); int stringWidth = label.getFontMetrics(labelFont).stringWidth(labelText); int componentWidth = label.getWidth(); // Find out how much the font can grow in width. double widthRatio = (double)componentWidth / (double)stringWidth; int newFontSize = (int)(labelFont.getSize() * widthRatio); int componentHeight = label.getHeight(); // Pick a new font size so it will not be larger than the height of label. int fontSizeToUse = Math.min(newFontSize, componentHeight); // Set the label's font size to the newly determined size. label.setFont(new Font(labelFont.getName(), Font.PLAIN, fontSizeToUse));
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof String) { renderer.setText((String) value); renderer.setFont(new Font((String) value, DEFAULT_FONT.getStyle(), DEFAULT_FONT.getSize() + 2)); } else { renderer.setText(""); } return renderer; } });
public static void main(String[] args) { //FontMeasurer.instance().getFontFor(7); float size = 12; Font currentFont = new Font("Sans", Font.BOLD, (int) size); System.out.println(currentFont.getSize()); currentFont = currentFont.deriveFont(--size); System.out.println(currentFont.getSize()); currentFont = currentFont.deriveFont(--size); System.out.println(currentFont.getSize()); currentFont = currentFont.deriveFont(--size); System.out.println(currentFont.getSize()); currentFont = currentFont.deriveFont(--size); System.out.println(currentFont.getSize()); currentFont = currentFont.deriveFont(--size); System.out.println(currentFont.getSize()); } }
/** * @noinspection ALL */ private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) { if (currentFont == null) return null; String resultName; if (fontName == null) { resultName = currentFont.getName(); } else { Font testFont = new Font(fontName, Font.PLAIN, 10); if (testFont.canDisplay('a') && testFont.canDisplay('1')) { resultName = fontName; } else { resultName = currentFont.getName(); } } return new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize()); }
int size = sampleTextPane.getFont().getSize(); if (size < 14) size = 14; sampleTextPane.setFont(unicodeFont.getFont().deriveFont((float)size));
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof String) { renderer.setText((String) value); renderer.setFont( new Font(DEFAULT_FONT.getName(), FONT_STYLE_CODES[index], DEFAULT_FONT.getSize() + 2)); } else { renderer.setText(""); } return renderer; } });
@Override public void initOptions() { Font f = null; String fontName = ServiceLocator.getInstance(IGlobalOptions.class).getProperty(PROP_PREFIX + "font"); String fontSizeStr = ServiceLocator.getInstance(IGlobalOptions.class).getProperty(PROP_PREFIX + "fontSize"); int fontSize = 12; if(fontSizeStr != null){ try{ fontSize = Integer.parseInt(fontSizeStr); } catch(NumberFormatException ex){ // leave the default font size of 12 } } // else leave default font size of 12 if(fontName == null){ LOG.info("Font configuration not available in configuration. Reverting to default font."); f = new Font(Font.DIALOG, Font.PLAIN, 12); } else{ f = new Font(fontName, Font.PLAIN, fontSize); } jl_font.setSelectedValue(f.getFamily(), true); jl_fontSize.setSelectedValue(String.valueOf(f.getSize()), true); ServiceLocator.getInstance(RESTViewImpl.class).setTextAreaFont(f); }
protected Font substituteFont(Font font) { String fontName = replaceFonts.getProperty(font.getName(), null); if (fontName != null) { Font newFont = new Font(fontName, font.getSize(), font.getStyle()); font = newFont.deriveFont(font.getSize2D()); } return font; }
/** * Workaround for Apple bug 3644261 - after using form editor, all boldface * fonts start showing up with incorrect metrics, such that all boldface * fonts in the entire IDE are displayed 12px below where they should be. * Embarrassing and awful. */ private static final Font deriveFont(Font f, int style) { // return f.deriveFont(style); // see #49973 for details. Font result = Utilities.isMac() ? new Font(f.getName(), style, f.getSize()) : f.deriveFont(style); return result; }
public void setTextFont(final String fontName) { // TODO: Need mapping between known QD font names and Java font names? Font current = graphics.getFont(); graphics.setFont(Font.decode(fontName).deriveFont(current.getStyle(), (float) current.getSize())); }
public void setDisplayedFont(Font font, boolean underline) { this.displayedFont = font; // The font we display needs to be smaller; the font will be // shown in its actual size in the preview panel. Font ourFont = font.deriveFont(getFont().getSize2D()); setFont(ourFont); setText(ourFont.getFamily() + " " + displayedFont.getSize() + (font.isBold() ? " Bold" : "") + (font.isItalic() ? " Italic" : "") + (underline ? " Underline" : "")); }
upButton.setMargin(new Insets(0, 0, 0, 0)); Font font = upButton.getFont(); upButton.setFont(new Font(font.getName(), font.getStyle(), font.getSize() - 2)); downButton.setMargin(new Insets(0, 0, 0, 0)); Font font = downButton.getFont(); downButton.setFont(new Font(font.getName(), font.getStyle(), font.getSize() - 2)); deleteButton.setMargin(new Insets(0, 0, 0, 0)); Font font = deleteButton.getFont(); deleteButton.setFont(new Font(font.getName(), font.getStyle(), font.getSize() - 2)); titlePanel.add(nameLabel); Font font = nameLabel.getFont(); nameLabel.setFont(new Font(font.getName(), Font.BOLD, font.getSize()));
int size = sampleTextPane.getFont().getSize(); if (size < 14) size = 14; sampleTextPane.setFont(unicodeFont.getFont().deriveFont((float)size));
private JPanel getHeaderPanel(Map<String, String> attributes) { JPanel headerPanel = new JPanel(new GridBagLayout()); headerPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 5, 0)); if (attributes != null) { Iterator<String> keys = attributes.keySet().iterator(); int row = 0; while (keys.hasNext()) { int fontSize = Integer.parseInt(PDFDebugger.configuration.getProperty( "headerFontSize", "" + headerPanel.getFont().getSize())); String key = keys.next(); JLabel encodingNameLabel = new JLabel(key + ": " + attributes.get(key)); encodingNameLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, fontSize)); encodingNameLabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0)); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = row++; gbc.weighty = 0.1; gbc.anchor = GridBagConstraints.LINE_START; headerPanel.add(encodingNameLabel, gbc); } } return headerPanel; }
public void setFont(Font font) { if (font == null) return; super.setFont(font); if (font.getName().equals("Symbol") || font.getName().equals("ZapfDingbats")) { Font newFont = new Font("Serif", font.getSize(), font.getStyle()); font = newFont.deriveFont(font.getSize2D()); } hostGraphics.setFont(font); }
private HSSFFont matchFont( Font matchFont ) { HSSFColor hssfColor = workbook.getCustomPalette() .findColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); if (hssfColor == null) hssfColor = workbook.getCustomPalette().findSimilarColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); boolean bold = (matchFont.getStyle() & Font.BOLD) != 0; boolean italic = (matchFont.getStyle() & Font.ITALIC) != 0; HSSFFont hssfFont = workbook.findFont(bold, hssfColor.getIndex(), (short)(matchFont.getSize() * 20), matchFont.getName(), italic, false, (short)0, (byte)0); if (hssfFont == null) { hssfFont = workbook.createFont(); hssfFont.setBold(bold); hssfFont.setColor(hssfColor.getIndex()); hssfFont.setFontHeight((short)(matchFont.getSize() * 20)); hssfFont.setFontName(matchFont.getName()); hssfFont.setItalic(italic); hssfFont.setStrikeout(false); hssfFont.setTypeOffset((short) 0); hssfFont.setUnderline((byte) 0); } return hssfFont; }