Example usage for java.awt Font PLAIN

List of usage examples for java.awt Font PLAIN

Introduction

In this page you can find the example usage for java.awt Font PLAIN.

Prototype

int PLAIN

To view the source code for java.awt Font PLAIN.

Click Source Link

Document

The plain style constant.

Usage

From source file:Main.java

/**
 * Sets font size and style for the specified component.
 *
 * @param component//from  w w  w  .j  ava2s  .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();/*w  w  w.  j a  v a  2s .com*/
    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:MainClass.java

public MainClass() {
    super();/*from  ww w  .  j  av  a2 s. co  m*/
    setSize(300, 200);

    textPane.setFont(new Font("Serif", Font.PLAIN, 24));

    // create some handy attribute sets
    SimpleAttributeSet red = new SimpleAttributeSet();
    StyleConstants.setForeground(red, Color.red);
    StyleConstants.setBold(red, true);
    SimpleAttributeSet blue = new SimpleAttributeSet();
    StyleConstants.setForeground(blue, Color.blue);
    SimpleAttributeSet italic = new SimpleAttributeSet();
    StyleConstants.setItalic(italic, true);
    StyleConstants.setForeground(italic, Color.orange);

    // add the text
    append("NULL ", null);
    append("Blue", blue);
    append("italic", italic);
    append("red", red);

    Container content = getContentPane();
    content.add(new JScrollPane(textPane), BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:IteratorTest.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String s = "Java Source and Support";
    Dimension d = getSize();/*from   www  .j  av  a 2s. c om*/

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font serifFont = new Font("Serif", Font.PLAIN, 48);
    Font sansSerifFont = new Font("Monospaced", Font.PLAIN, 48);

    AttributedString as = new AttributedString(s);
    as.addAttribute(TextAttribute.FONT, serifFont);
    as.addAttribute(TextAttribute.FONT, sansSerifFont, 2, 5);
    as.addAttribute(TextAttribute.FOREGROUND, Color.red, 5, 6);
    as.addAttribute(TextAttribute.FOREGROUND, Color.red, 16, 17);

    g2.drawString(as.getIterator(), 40, 80);
}

From source file:RollingText.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "Java Source and Support.";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);//w  w w  .  ja v a 2  s .  c  o  m

    GlyphVector gv = font.createGlyphVector(frc, s);
    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}

From source file:RotatedText.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "111111111111111111111111111111";

    Font font = new Font("Courier", Font.PLAIN, 12);
    g2d.translate(20, 20);//  w  w  w .j a v a 2s.  c  om

    FontRenderContext frc = g2d.getFontRenderContext();

    GlyphVector gv = font.createGlyphVector(frc, s);
    int length = gv.getNumGlyphs();
    System.out.println(length);

}

From source file:RotatedText.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "111111111111111111111111111111";

    Font font = new Font("Courier", Font.PLAIN, 12);
    g2d.translate(20, 20);//from   www.  j av a2  s . c o  m

    FontRenderContext frc = g2d.getFontRenderContext();

    GlyphVector gv = font.createGlyphVector(frc, s);
    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate((double) i / (double) (length - 1) * Math.PI / 3);

        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2d.fill(transformedGlyph);
    }
}

From source file:Clock.java

private void drawStructure(Graphics g) {
    g.setFont(new Font("TimesRoman", Font.PLAIN, 14));
    g.setColor(Color.blue);//  w w  w . j a  v a  2  s.co  m
    g.drawOval(xcenter - 50, ycenter - 50, 100, 100);
    g.setColor(Color.darkGray);
    g.drawString("9", xcenter - 45, ycenter + 3);
    g.drawString("3", xcenter + 40, ycenter + 3);
    g.drawString("12", xcenter - 5, ycenter - 37);
    g.drawString("6", xcenter - 3, ycenter + 45);

}

From source file:FontSizeAnimation.java

public void paint(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;

    Font font = new Font("Dialog", Font.PLAIN, x);
    g2d.setFont(font);//  w  w w  . ja va 2s . c  o  m

    FontMetrics fm = g2d.getFontMetrics();
    String s = "Java";

    int w = (int) getSize().getWidth();
    int h = (int) getSize().getHeight();

    int stringWidth = fm.stringWidth(s);

    g2d.drawString(s, (w - stringWidth) / 2, h / 2);
}

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font font = new Font("Serif", Font.PLAIN, 96);
    g2.setFont(font);//w  ww  .j  a v  a  2s . c o m

    g2.drawString("Please \u062e\u0644\u0639 slowly.", 40, 80);
}