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(DEFAULT_FONT.getName(), FONT_STYLE_CODES[index], DEFAULT_FONT.getSize() + 2)); } else { renderer.setText(""); } return renderer; } });
/** * @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()); }
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()));
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()));
@Override public void drawString(String str, int x, int y) { if (str == null || str.isEmpty()) return; Font excelFont = font; if ( font.getName().equals( "SansSerif" ) ) { excelFont = new Font( "Arial", font.getStyle(), (int) ( font.getSize() / verticalPixelsPerPoint ) ); } else { excelFont = new Font( font.getName(), font.getStyle(), (int) ( font.getSize() / verticalPixelsPerPoint )); } FontDetails d = StaticFontMetrics.getFontDetails( excelFont ); int width = d.getStringWidth( str ) * 8 + 12; int height = (int) ( ( font.getSize() / verticalPixelsPerPoint ) + 6 ) * 2; y -= ( font.getSize() / verticalPixelsPerPoint ) + 2 * verticalPixelsPerPoint; // we want to draw the shape from the top-left HSSFTextbox textbox = escherGroup.createTextbox( new HSSFChildAnchor( x, y, x + width, y + height ) ); textbox.setNoFill( true ); textbox.setLineStyle( HSSFShape.LINESTYLE_NONE ); HSSFRichTextString s = new HSSFRichTextString( str ); HSSFFont hssfFont = matchFont( excelFont ); s.applyFont( hssfFont ); textbox.setString( s ); }
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; }
/** * 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; }
Image newimg = img.getScaledInstance(GUISizeHelper.menuFont.getSize(), GUISizeHelper.menuFont.getSize(), java.awt.Image.SCALE_SMOOTH); btnStateWaiting.setIcon(new ImageIcon(newimg)); newimg = img.getScaledInstance(GUISizeHelper.menuFont.getSize(), GUISizeHelper.menuFont.getSize(), java.awt.Image.SCALE_SMOOTH); btnStateActive.setIcon(new ImageIcon(newimg)); jPanelBottom.setPreferredSize(newDimension); jButtonFooterNext.setFont(GUISizeHelper.menuFont); jLabelFooterLabel.setFont(new Font(GUISizeHelper.menuFont.getName(), Font.BOLD, GUISizeHelper.menuFont.getSize())); jLabelFooterText.setFont(GUISizeHelper.menuFont);
panel2.add(spacer1, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); final JLabel label1 = new JLabel(); label1.setFont(new Font(label1.getFont().getName(), Font.BOLD, 14)); label1.setText("Software vulnerability scanner"); panel2.add(label1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); panel2.add(label2, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JLabel label3 = new JLabel(); label3.setFont(new Font(label3.getFont().getName(), Font.BOLD, label3.getFont().getSize())); label3.setHorizontalAlignment(2); label3.setIcon(new ImageIcon(getClass().getResource("/logo_small.png"))); panel3.add(btnTblSoftwareClear, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JLabel label6 = new JLabel(); label6.setFont(new Font(label6.getFont().getName(), Font.BOLD, label6.getFont().getSize())); label6.setText("Vulnerable Software"); panel3.add(label6, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); panel3.add(separator1, new GridConstraints(4, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); final JLabel label7 = new JLabel(); label7.setFont(new Font(label7.getFont().getName(), Font.BOLD, label7.getFont().getSize())); label7.setText("Possible vulnerable software uses specific paths"); panel3.add(label7, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); tabbedPane1.addTab("Options", panel4); final JLabel label8 = new JLabel(); label8.setFont(new Font(label8.getFont().getName(), Font.BOLD, label8.getFont().getSize())); label8.setText("Scan options"); panel4.add(label8, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
StyleSheet css2 = new StyleSheet(); Font f = new JList().getFont(); int size = f.getSize(); try { css2.addRule(new StringBuffer("body { font-size: ").append(size) // NOI18N .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N css2.addStyleSheet(css); htmlkit.setStyleSheet(css2);
/** * Writes <tag>value</tag> to output stream * * @param tag XML tag name * @param value value to be placed between <code><tag></code> and <code></tag></code> */ public void writeTag(String tag, Font value) { startTag(tag); writeTag("name", value.getName()); int style = value.getStyle(); if ((style & Font.BOLD) != 0 && (style & Font.ITALIC) != 0) { writeTag("style", "BOLDITALIC"); } else if ((style & Font.BOLD) != 0) { writeTag("style", "BOLD"); } else if ((style & Font.ITALIC) != 0) { writeTag("style", "ITALIC"); } else { writeTag("style", "PLAIN"); } writeTag("size", value.getSize()); closeTag(); }
/** * Encode font into a human-readable string.<br> * * @param font * Font object. * @return String extracted from the given Font object. */ private String encodeFont(final Font font) { // Encode font into "fontname-style-pointsize" string return font.getName() + "-" + font.getStyle() + "-" + font.getSize(); }
/** Modify the given font according to the font-mode */ private Font modifyFont(Font f) { return new Font( ((fontMode & FONT_MODE_APPLY_NAME) != 0) ? font.getName() : f.getName(), ((fontMode & FONT_MODE_APPLY_STYLE) != 0) ? font.getStyle() : f.getStyle(), ((fontMode & FONT_MODE_APPLY_SIZE) != 0) ? font.getSize() : f.getSize() ); }