Example usage for java.awt Font Font

List of usage examples for java.awt Font Font

Introduction

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

Prototype

private Font(String name, int style, float sizePts) 

Source Link

Usage

From source file:ShadowText.java

public void paint(Graphics g) {
    String text = "Hello World";
    int x = 10;//from w ww  .j  a  v a 2  s. co  m
    int y = 100;

    Font font = new Font("Georgia", Font.ITALIC, 50);
    Graphics2D g1 = (Graphics2D) g;

    TextLayout textLayout = new TextLayout(text, font, g1.getFontRenderContext());
    g1.setPaint(new Color(150, 150, 150));
    textLayout.draw(g1, x + 3, y + 3);

    g1.setPaint(Color.BLACK);
    textLayout.draw(g1, x, y);
}

From source file:JTextAreaI18N.java

public JTextAreaI18N() {
    GraphicsEnvironment.getLocalGraphicsEnvironment();
    JTextArea textArea = new JTextArea(davidMessage);
    textArea.setFont(new Font("LucidaSans", Font.PLAIN, 40));
    this.getContentPane().add(textArea);
    textArea.setVisible(true);// w w  w  .  j  a v  a  2 s .c  o m
}

From source file:Main.java

public Main() {
    super("TrueType Font Demonstration");

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.getAllFonts();//  www. j a v  a  2 s  . c o m

    Font font = new Font("Jokerman", Font.PLAIN, 35);
    JLabel textLabel = new JLabel(textMessage);
    textLabel.setFont(font);

    getContentPane().add(textLabel);
    setVisible(true);
}

From source file:TrueTypeTest.java

public TrueTypeTest() {
    super("TrueType Font Demonstration");

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.getAllFonts();/*from ww  w  .  j  a  v a2  s  . c om*/

    Font font = new Font("Jokerman", Font.PLAIN, 35);
    JLabel textLabel = new JLabel(textMessage);
    textLabel.setFont(font);

    getContentPane().add(textLabel);
    show();
}

From source file:FontPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Font f = new Font("SansSerif", Font.BOLD, 14);
    Font fi = new Font("SansSerif", Font.BOLD + Font.ITALIC, 14);
    FontMetrics fm = g.getFontMetrics(f);
    FontMetrics fim = g.getFontMetrics(fi);

    String s1 = "Java ";
    String s2 = "Source and Support";
    String s3 = " at www.java2s.com";
    int width1 = fm.stringWidth(s1);
    int width2 = fim.stringWidth(s2);
    int width3 = fm.stringWidth(s3);

    Dimension d = getSize();/*from   w  ww. java2  s . com*/
    int cx = (d.width - width1 - width2 - width3) / 2;
    int cy = (d.height - fm.getHeight()) / 2 + fm.getAscent();

    g.setFont(f);
    g.drawString(s1, cx, cy);
    cx += width1;
    g.setFont(fi);
    g.drawString(s2, cx, cy);
    cx += width2;
    g.setFont(f);
    g.drawString(s3, cx, cy);
}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Font font = new Font("Serif", Font.PLAIN, 12);
    g.setFont(font);//from www .jav  a2 s. c  o m
    g.drawString("a String", 10, 10);

    FontMetrics fontMetrics = g.getFontMetrics();
    g.drawString("aString", 10, 10 + fontMetrics.getAscent());
}

From source file:RevalidateExample.java

public RevalidateExample() {
    super("Revalidation Demo");
    setSize(300, 150);//from   w  w w.j av  a2s . c o  m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Font font = new Font("Dialog", Font.PLAIN, 10);
    final JButton b = new JButton("Add");
    b.setFont(font);

    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    c.add(b);

    b.addActionListener(new ActionListener() {
        // Increase the size of the button's font each time it's clicked

        int size = 20;

        public void actionPerformed(ActionEvent ev) {
            b.setFont(new Font("Dialog", Font.PLAIN, ++size));
            b.revalidate(); // invalidates the button & validates its root pane
        }
    });
}

From source file:HelloInJapanese.java

public HelloInJapanese(String characters) {
    Font theFont = new Font("Bitstream Cyberbit", Font.PLAIN, 20);
    JTextArea area = new JTextArea(characters, 2, 30);
    area.setFont(theFont);/* w  ww .j a  v  a  2 s . c  o  m*/
    area.setLineWrap(true);
    JScrollPane scrollpane = new JScrollPane(area);
    add(scrollpane);
}

From source file:com.uttesh.pdfngreport.util.chart.ChartStyle.java

/**
 * this method will set the style theme for pie chart.
 *
 * @see org.jfree.chart.StandardChartTheme
 * @param chart/*from  w w w . ja  v  a2s  . c o  m*/
 */
public static void theme(JFreeChart chart) {
    String fontName = "Lucida Sans";

    StandardChartTheme theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();

    theme.setTitlePaint(Color.decode("#4572a7"));
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 16)); //title
    theme.setLargeFont(new Font(fontName, Font.BOLD, 15)); //axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 11));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);
    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel("Some label text");
    label.setBorder(BorderFactory.createLineBorder(Color.green));
    label.setFont(new Font("Serif", Font.ITALIC, 16));

    getContentPane().add(label);//from  ww  w . ja  v a  2  s .  c o  m
    pack();
    setVisible(true);
}