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:MainClass.java

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

    String s = "\"www.java2s.com,\" www.java2s.com";

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);

    AttributedString as = new AttributedString(s);
    as.addAttribute(TextAttribute.FONT, plainFont);

    g2.drawString(as.getIterator(), 24, 70);

}

From source file:Main.java

public void paint(Graphics g) {
    BufferedImage bim;/*from w  w  w . j av  a  2 s  . com*/

    TexturePaint tp;

    String mesg = "www.java2s.com";

    Font myFont = new Font("Lucida Regular", Font.BOLD, 72);

    Color[] colors = { Color.red, Color.blue, Color.yellow, };

    int width = 8, height = 8;
    bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bim.createGraphics();
    for (int i = 0; i < width; i++) {
        g2.setPaint(colors[(i / 2) % colors.length]);
        g2.drawLine(0, i, i, 0);
        g2.drawLine(width - i, height, width, height - i);
    }
    Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
    tp = new TexturePaint(bim, r);
    System.out.println(tp.getAnchorRect());

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setPaint(tp);
    g2d.setFont(myFont);
    g2d.drawString(mesg, 20, 100);
}

From source file:Main.java

public void paint(Graphics g) {
    BufferedImage bim;// w w w  .  j a va2 s . com

    TexturePaint tp;

    String mesg = "www.java2s.com";

    Font myFont = new Font("Lucida Regular", Font.BOLD, 72);

    Color[] colors = { Color.red, Color.blue, Color.yellow, };

    int width = 8, height = 8;
    bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bim.createGraphics();
    for (int i = 0; i < width; i++) {
        g2.setPaint(colors[(i / 2) % colors.length]);
        g2.drawLine(0, i, i, 0);
        g2.drawLine(width - i, height, width, height - i);
    }
    Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
    tp = new TexturePaint(bim, r);
    System.out.println(tp.getImage());

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setPaint(tp);
    g2d.setFont(myFont);
    g2d.drawString(mesg, 20, 100);
}

From source file:Main.java

public void paint(Graphics g) {
    BufferedImage bim;//from  w w  w . j  a  va 2  s.c o m

    TexturePaint tp;

    String mesg = "www.java2s.com";

    Font myFont = new Font("Lucida Regular", Font.BOLD, 72);

    Color[] colors = { Color.red, Color.blue, Color.yellow, };

    int width = 8, height = 8;
    bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bim.createGraphics();
    for (int i = 0; i < width; i++) {
        g2.setPaint(colors[(i / 2) % colors.length]);
        g2.drawLine(0, i, i, 0);
        g2.drawLine(width - i, height, width, height - i);
    }
    Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
    tp = new TexturePaint(bim, r);
    System.out.println(tp.getTransparency());

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setPaint(tp);
    g2d.setFont(myFont);
    g2d.drawString(mesg, 20, 100);
}

From source file:Main.java

public void paint(Graphics g) {
    BufferedImage bim;/*from   www .j  av a  2s.c  o  m*/

    TexturePaint tp;

    String mesg = "www.java2s.com";

    Font myFont = new Font("Lucida Regular", Font.BOLD, 72);

    Color[] colors = { Color.red, Color.blue, Color.yellow, };

    int width = 8, height = 8;
    bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bim.createGraphics();
    for (int i = 0; i < width; i++) {
        g2.setPaint(colors[(i / 2) % colors.length]);
        g2.drawLine(0, i, i, 0);
        g2.drawLine(width - i, height, width, height - i);
    }
    Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
    tp = new TexturePaint(bim, r);
    tp.createContext(ColorModel.getRGBdefault(), new Rectangle(10, 10, 20, 20), null, null, null);

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setPaint(tp);
    g2d.setFont(myFont);
    g2d.drawString(mesg, 20, 100);
}

From source file:pingsnmpapp.classPieGraph.java

public JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Grfica de Disco", // chart title
            dataset, // data
            true, // include legend
            true, false);//w  ww .ja  va 2  s .c  o  m

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;

}

From source file:Main.java

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setFont(new Font("arial", Font.PLAIN, 24));
    g.drawString("java2s.com", 200, 200);
}

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, 72);
    g2.setFont(font);//w w  w  .ja  v a  2 s .  c o  m

    String s = "www.java2s.com";
    float x = 50, y = 150;

    FontRenderContext frc = g2.getFontRenderContext();
    float width = (float) font.getStringBounds(s, frc).getWidth();
    Line2D baseline = new Line2D.Float(x, y, x + width, y);
    g2.setPaint(Color.lightGray);
    g2.draw(baseline);

    // Draw the ascent.
    LineMetrics lm = font.getLineMetrics(s, frc);
    Line2D ascent = new Line2D.Float(x, y - lm.getAscent(), x + width, y - lm.getAscent());
    g2.draw(ascent);

    // Draw the descent.
    Line2D descent = new Line2D.Float(x, y + lm.getDescent(), x + width, y + lm.getDescent());
    g2.draw(descent);

    // Draw the leading.
    Line2D leading = new Line2D.Float(x, y + lm.getDescent() + lm.getLeading(), x + width,
            y + lm.getDescent() + lm.getLeading());
    g2.draw(leading);

    // Render the string.
    g2.setPaint(Color.black);
    g2.drawString(s, x, y);
}

From source file:Main.java

public static Object getPropertyValue(Element element) {
    NamedNodeMap map = element.getAttributes();
    map.removeNamedItem(NAME_ATTR);/* www  .  ja v  a 2s .com*/

    if (map.item(0).getNodeName().equals(STRING_ATTR)) {
        return map.item(0).getNodeValue();
    } else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) {
        return new Integer(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) {
        return new Double(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) {
        return new Float(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) {
        return Boolean.valueOf(map.item(0).getNodeValue());
    } else if (map.item(0).getNodeName().equals(COLOR_ATTR)) {
        String[] rgb = map.item(0).getNodeValue().split(",");
        return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2]));
    } else if (map.item(0).getNodeName().equals(FONT_ATTR)) {
        String[] font = map.item(0).getNodeValue().split(",");
        return new Font(font[0], new Integer(font[1]), new Integer(font[2]));
    } else {
        return null;
    }
}

From source file:Main.java

public CheckBoxFrame() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    label = new JLabel("The quick brown fox jumps over the lazy dog.");
    label.setFont(new Font("Serif", Font.PLAIN, FONTSIZE));
    add(label, BorderLayout.CENTER);

    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int mode = 0;
            if (bold.isSelected())
                mode += Font.BOLD;
            if (italic.isSelected())
                mode += Font.ITALIC;
            label.setFont(new Font("Serif", mode, FONTSIZE));
        }/* w ww.  j av a2s  . com*/
    };

    JPanel buttonPanel = new JPanel();

    bold = new JCheckBox("Bold");
    bold.addActionListener(listener);
    buttonPanel.add(bold);

    italic = new JCheckBox("Italic");
    italic.addActionListener(listener);
    buttonPanel.add(italic);

    add(buttonPanel, BorderLayout.SOUTH);
}