List of usage examples for java.awt Font ITALIC
int ITALIC
To view the source code for java.awt Font ITALIC.
Click Source Link
From source file:Main.java
public void paint(Graphics g) { Font f = g.getFont();/*from w w w .j a v a2s . c om*/ int fontSize = f.getSize(); int fontStyle = f.getStyle(); String msg = ", Size: " + fontSize + ", Style: "; if ((fontStyle & Font.BOLD) == Font.BOLD) msg += "Bold "; if ((fontStyle & Font.ITALIC) == Font.ITALIC) msg += "Italic "; if ((fontStyle & Font.PLAIN) == Font.PLAIN) msg += "Plain "; g.drawString(msg, 4, 16); }
From source file:Main.java
/** * Sets font size and style for the specified component. * * @param component/*from w w w . j a v a 2s .c om*/ * component to modify * @param fontSize * new font size * @param bold * whether should set bold font or not * @param italic * whether should set italic font or not * @param <C> * component type * @return modified component */ public static <C extends Component> C setFontSizeAndStyle(final C component, final int fontSize, final boolean bold, final boolean italic) { final int style = bold && italic ? Font.BOLD | Font.ITALIC : bold ? Font.BOLD : italic ? Font.ITALIC : Font.PLAIN; return setFontSizeAndStyle(component, fontSize, style); }
From source file:Main.java
public void paint(Graphics g) { Font f = g.getFont();//from www. j a v a 2 s .co m String fontName = f.getName(); String fontFamily = f.getFamily(); int fontSize = f.getSize(); int fontStyle = f.getStyle(); String msg = "Family: " + fontName; msg += ", Font: " + fontFamily; msg += ", Size: " + fontSize + ", Style: "; if ((fontStyle & Font.BOLD) == Font.BOLD) msg += "Bold "; if ((fontStyle & Font.ITALIC) == Font.ITALIC) msg += "Italic "; if ((fontStyle & Font.PLAIN) == Font.PLAIN) msg += "Plain "; g.drawString(msg, 4, 16); }
From source file:Main.java
/** * Changes font to italic for the specified component. * * @param component/* ww w . ja v a2s .c om*/ * component to modify * @param apply * whether to apply font changes or not * @param <C> * component type * @return modified component */ public static <C extends Component> C setItalicFont(final C component, final boolean apply) { if (apply && component != null && component.getFont() != null) { component.setFont(component.getFont().deriveFont(Font.ITALIC)); } return component; }
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);// w w w. j a 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:FontDerivation.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Create a 1-point font. Font font = new Font("Serif", Font.PLAIN, 1); float x = 20, y = 20; Font font24 = font.deriveFont(24.0f); g2.setFont(font24);/*from ww w . j a v a 2 s . co m*/ g2.drawString("font.deriveFont(24.0f)", x, y += 30); Font font24italic = font24.deriveFont(Font.ITALIC); g2.setFont(font24italic); g2.drawString("font24.deriveFont(Font.ITALIC)", x, y += 30); AffineTransform at = new AffineTransform(); at.shear(.2, 0); Font font24shear = font24.deriveFont(at); g2.setFont(font24shear); g2.drawString("font24.deriveFont(at)", x, y += 30); Hashtable attributes = new Hashtable(); attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); Font font24bold = font24.deriveFont(attributes); g2.setFont(font24bold); g2.drawString("font24.deriveFont(attributes)", x, y += 30); }
From source file:Main.java
public Main() { setSize(350, 400);/*from w w w .j av a 2 s. co m*/ attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, 0, text.length()); attribString.addAttribute(TextAttribute.FONT, new Font("sanserif", Font.ITALIC, 20), 0, text.length()); }
From source file:StylesExample8.java
public static void createDocumentStyles(StyleContext sc) { Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE); // Create and add the main document style Style mainStyle = sc.addStyle(mainStyleName, defaultStyle); StyleConstants.setLeftIndent(mainStyle, 16); StyleConstants.setRightIndent(mainStyle, 16); StyleConstants.setFirstLineIndent(mainStyle, 16); StyleConstants.setFontFamily(mainStyle, "serif"); StyleConstants.setFontSize(mainStyle, 12); // Create and add the constant width style Style cwStyle = sc.addStyle(charStyleName, null); StyleConstants.setFontFamily(cwStyle, "monospaced"); StyleConstants.setForeground(cwStyle, Color.green); // Create and add the heading style Style heading2Style = sc.addStyle(heading2StyleName, null); StyleConstants.setForeground(heading2Style, Color.red); StyleConstants.setFontSize(heading2Style, 16); StyleConstants.setFontFamily(heading2Style, "serif"); StyleConstants.setBold(heading2Style, true); StyleConstants.setLeftIndent(heading2Style, 8); StyleConstants.setFirstLineIndent(heading2Style, 0); // Create and add the Component style Class thisClass = StylesExample8.class; URL url = thisClass.getResource("java2s.gif"); ImageIcon icon = new ImageIcon(url); JLabel comp = new JLabel("Displaying text with attributes", icon, JLabel.CENTER); comp.setVerticalTextPosition(JLabel.BOTTOM); comp.setHorizontalTextPosition(JLabel.CENTER); comp.setFont(new Font("serif", Font.BOLD | Font.ITALIC, 14)); Style componentStyle = sc.addStyle(componentStyleName, null); StyleConstants.setComponent(componentStyle, comp); // The paragraph style for the component Style compParagraphStyle = sc.addStyle(compParaName, null); StyleConstants.setSpaceAbove(compParagraphStyle, (float) 16.0); }
From source file:TextPaneElements.java
public static void createDocumentStyles(StyleContext sc) { Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE); // Create and add the main document style Style mainStyle = sc.addStyle(mainStyleName, defaultStyle); StyleConstants.setLeftIndent(mainStyle, 16); StyleConstants.setRightIndent(mainStyle, 16); StyleConstants.setFirstLineIndent(mainStyle, 16); StyleConstants.setFontFamily(mainStyle, "serif"); StyleConstants.setFontSize(mainStyle, 12); // Create and add the constant width style Style cwStyle = sc.addStyle(charStyleName, null); StyleConstants.setFontFamily(cwStyle, "monospaced"); StyleConstants.setForeground(cwStyle, Color.green); // Create and add the heading style Style heading2Style = sc.addStyle(heading2StyleName, null); StyleConstants.setForeground(heading2Style, Color.red); StyleConstants.setFontSize(heading2Style, 16); StyleConstants.setFontFamily(heading2Style, "serif"); StyleConstants.setBold(heading2Style, true); StyleConstants.setLeftIndent(heading2Style, 8); StyleConstants.setFirstLineIndent(heading2Style, 0); // Create and add the Component style Class thisClass = TextPaneElements.class; URL url = thisClass.getResource("java2s.gif"); ImageIcon icon = new ImageIcon(url); JLabel comp = new JLabel("Displaying text with attributes", icon, JLabel.CENTER); comp.setVerticalTextPosition(JLabel.BOTTOM); comp.setHorizontalTextPosition(JLabel.CENTER); comp.setFont(new Font("serif", Font.BOLD | Font.ITALIC, 14)); Style componentStyle = sc.addStyle(componentStyleName, null); StyleConstants.setComponent(componentStyle, comp); // The paragraph style for the component Style compParagraphStyle = sc.addStyle(compParaName, null); StyleConstants.setSpaceAbove(compParagraphStyle, (float) 16.0); }
From source file:CheckBoxDemo.java
public void actionPerformed(ActionEvent evt) { int m = (bold.isSelected() ? Font.BOLD : 0) + (italic.isSelected() ? Font.ITALIC : 0); fontLabel.setFont(new Font("SansSerif", m, 12)); }