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: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 w  ww . ja  v a  2 s.  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);/*  w  w  w  . jav a2s. 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  . jav a2s  . 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:org.jfree.chart.demo.DrawStringPanel.java

public DrawStringPanel(String s, boolean flag) {
    text = "Hello World";
    anchor = TextAnchor.TOP_LEFT;/*  w  w w .  j  a v a2  s.  co m*/
    rotationAnchor = TextAnchor.TOP_LEFT;
    font = new Font("Serif", 0, 12);
    text = s;
    rotate = flag;
}

From source file:org.jfree.chart.demo.XYBarChartDemo1.java

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("State Executions - USA", "Year", true,
            "Number of People", intervalxydataset, PlotOrientation.VERTICAL, true, false, false);
    jfreechart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do",
            new Font("Dialog", 2, 10)));
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
    xyitemrenderer.setBaseToolTipGenerator(standardxytooltipgenerator);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.white);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);/*from  www.j ava2 s.c om*/
    dateaxis.setUpperMargin(0.01D);
    return jfreechart;
}

From source file:Main.java

public Main() {

    someComboBox.setFont(new Font("Serif", Font.BOLD, 16));
    someComboBox.setEditable(true);//from  w w  w.j  a v a2 s. c  o m
    someComboBox.getEditor().getEditorComponent().setBackground(Color.YELLOW);
    ((JTextField) someComboBox.getEditor().getEditorComponent()).setBackground(Color.YELLOW);

    JTextField text = ((JTextField) editableComboBox.getEditor().getEditorComponent());
    text.setBackground(Color.YELLOW);
    JComboBox coloredArrowsCombo = editableComboBox;
    Component[] comp = coloredArrowsCombo.getComponents();
    for (int i = 0; i < comp.length; i++) {
        if (comp[i] instanceof MetalComboBoxButton) {
            MetalComboBoxButton coloredArrowsButton = (MetalComboBoxButton) comp[i];
            coloredArrowsButton.setBackground(null);
            break;
        }
    }

    non_EditableComboBox.setFont(new Font("Serif", Font.BOLD, 16));

    frame = new JFrame();
    frame.setLayout(new GridLayout(0, 1, 10, 10));
    frame.add(someComboBox);
    frame.add(editableComboBox);
    frame.add(non_EditableComboBox);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocation(100, 100);
    frame.pack();
    frame.setVisible(true);
}

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);//from  w w  w  .j a va 2s . c  om

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

public Main() {
    super();//from w w  w.  j  a  v  a 2s .c o  m
    setSize(450, 350);
    for (int k = 0; k < FontName.length; k++)
        fonts[k] = new Font(FontName[k], Font.PLAIN, 12);

    JMenuBar menuBar = createMenuBar();
    setJMenuBar(menuBar);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setVisible(true);
}

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 w w . j a va2 s .  com

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

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);/*from www .j  ava2s .  com*/

    g2.drawString("jade", 40, 120);
}