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

/**
 * The init method is called when the browser first starts the applet. It
 * sets up the Label component and obtains a DateFormat object
 *///from   ww  w.  ja v  a 2  s .  co  m
public void init() {
    time = new Label();
    time.setFont(new Font("helvetica", Font.BOLD, 12));
    time.setAlignment(Label.CENTER);
    setLayout(new BorderLayout());
    add(time, BorderLayout.CENTER);
    timeFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM);
}

From source file:com.compomics.pepshell.view.statistics.JFreeChartPanel.java

private static void setupPlot(CategoryPlot categoryPlot) {
    categoryPlot.setBackgroundPaint(Color.white);
    categoryPlot.setRangeGridlinePaint(Color.black);
    // hide the border of the sorrounding box
    categoryPlot.setOutlinePaint(Color.white);
    // get domanin and range axes
    CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    ValueAxis rangeAxis = categoryPlot.getRangeAxis();
    // set label paint for axes to black
    domainAxis.setLabelPaint(Color.black);
    rangeAxis.setLabelPaint(Color.black);
    // set font for labels, both on domain and range axes
    domainAxis.setLabelFont(new Font("Tahoma", Font.BOLD, 12));
    rangeAxis.setLabelFont(new Font("Tahoma", Font.BOLD, 12));

}

From source file:no.imr.sea2data.guibase.chart.XYBarChart.java

public XYBarChart() {
    dataset = new XYSeriesCollection(new XYSeries("Series 1"));
    JFreeChart chart = ChartFactory.createXYBarChart("", "X axis", false, "Y axis", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setPaint(Color.black);
    chart.getTitle().setFont(new Font("SansSerif", Font.PLAIN, 12));
    chart.addSubtitle(trendLegend);//from   w w w  .j ava2 s  .c  om
    chart.addSubtitle(trendLegend2);
    trendLegend.setPosition(RectangleEdge.TOP);
    trendLegend2.setPosition(RectangleEdge.TOP);
    plot = (XYPlot) chart.getPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setShadowVisible(false);
    chartPanel = new ChartPanel(chart);
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
}

From source file:D20140128.ApacheXMLGraphicsTest.EPSColorsExample.java

/**
 * Creates an EPS file. The contents are painted using a Graphics2D
 * implementation that generates an EPS file.
 *
 * @param outputFile the target file//from   ww w . j  a  va2 s  . c  om
 * @throws IOException In case of an I/O error
 */
public static void generateEPSusingJava2D(File outputFile) throws IOException {
    OutputStream out = new java.io.FileOutputStream(outputFile);
    out = new java.io.BufferedOutputStream(out);
    try {
        //Instantiate the EPSDocumentGraphics2D instance
        EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
        g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());

        //Set up the document size
        g2d.setupDocument(out, 400, 200); //400pt x 200pt

        //Paint a bounding box
        g2d.drawRect(0, 0, 400, 200);

        g2d.setFont(new Font("sans-serif", Font.BOLD, 14));
        g2d.drawString("Color usage example:", 10, 20);
        g2d.setFont(new Font("sans-serif", Font.PLAIN, 12));
        g2d.drawString("RGB", 10, 84);
        g2d.drawString("CMYK", 60, 84);
        g2d.drawString("(Lab)", 110, 84);
        g2d.drawString("(Named)", 160, 84);

        //We're creating a few boxes all filled with some variant of the
        //"Postgelb" (postal yellow) color as used by Swiss Post.
        Color colRGB = new Color(255, 204, 0);
        g2d.setColor(colRGB);
        g2d.fillRect(10, 30, 40, 40);

        //Just convert RGB to CMYK and use that
        float[] compsRGB = colRGB.getColorComponents(null);
        DeviceCMYKColorSpace cmykCS = ColorSpaces.getDeviceCMYKColorSpace();
        float[] compsCMYK = cmykCS.fromRGB(compsRGB);
        Color colCMYK = DeviceCMYKColorSpace.createCMYKColor(compsCMYK);
        g2d.setColor(colCMYK);
        g2d.fillRect(60, 30, 40, 40);

        //Try CIELab (not implemented, yet)
        CIELabColorSpace d50 = ColorSpaces.getCIELabColorSpaceD50();
        Color colLab = d50.toColor(83.25f, 16.45f, 96.89f, 1.0f);
        g2d.setColor(colLab);
        g2d.fillRect(110, 30, 40, 40);

        //Try named color (Separation, not implemented, yet)
        float[] c1xyz = d50.toCIEXYZNative(83.25f, 16.45f, 96.89f);
        NamedColorSpace postgelb = new NamedColorSpace("Postgelb", c1xyz);
        Color colNamed = new Color(postgelb, new float[] { 1.0f }, 1.0f);
        g2d.setColor(colNamed);
        g2d.fillRect(160, 30, 40, 40);

        //Cleanup
        g2d.finish();
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.ouc.cpss.view.ProfitChartBuilder.java

public static JFreeChart createJFreeChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart("?", "", "?",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    // ?//from www.ja  v  a 2  s.  c o  m
    LegendTitle legendTitle = chart.getLegend(0);
    // 
    legendTitle.setItemFont(new Font("", Font.BOLD, 18));
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    // ?
    org.jfree.chart.axis.CategoryAxis categoryAxis = plot.getDomainAxis();
    // 
    categoryAxis.setLabelFont(new Font("", Font.BOLD, 18));

    // 
    categoryAxis.setTickLabelFont(new Font("", Font.BOLD, 12));
    // ?
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    // 
    numberAxis.setLabelFont(new Font("", Font.BOLD, 14));

    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());//

    CategoryItemRenderer xylineandshaperenderer = plot.getRenderer();
    xylineandshaperenderer.setBaseItemLabelsVisible(true);
    xylineandshaperenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.BASELINE_RIGHT));
    xylineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    return chart;
}

From source file:org.martus.client.reports.MartusChartTheme.java

public MartusChartTheme() {
    super("Martus");

    // NOTE: JFreeChart default is "Tahoma", which somehow maps to Dialog,
    // which for some reason (in J6) doesn't fall back to the fallback fonts, 
    // and therefore doesn't work in Armenian, Bangla, Khmer, or Nepali 
    setExtraLargeFont(new Font(FontHandler.getDefaultFontName(), Font.BOLD, 20));
    setLargeFont(new Font(FontHandler.getDefaultFontName(), Font.BOLD, 14));
    setRegularFont(new Font(FontHandler.getDefaultFontName(), Font.PLAIN, 12));
    setSmallFont(new Font(FontHandler.getDefaultFontName(), Font.PLAIN, 10));
}

From source file:com.tencent.wstt.apt.chart.CPURealTimeChart.java

@Override
public JFreeChart createChart() {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("CPU", "", "CPU%", dataset,
            true, true, false);// w w w .j  av a 2  s. c  o  m

    //??
    chart.getTitle().setFont(new Font("", Font.BOLD, 20));

    XYPlot xyPlot = (XYPlot) chart.getXYPlot();
    ValueAxis domainAxis = xyPlot.getDomainAxis();
    ValueAxis rangeAxis = xyPlot.getRangeAxis();

    domainAxis.setLabelFont(new Font("", Font.BOLD, 14));
    domainAxis.setTickLabelFont(new Font("", Font.BOLD, 12));

    rangeAxis.setLabelFont(new Font("", Font.BOLD, 14));
    rangeAxis.setTickLabelFont(new Font("", Font.BOLD, 12));
    return chart;
}

From source file:Main.java

public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
        int column) {
    JTextField editor = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);

    if (value != null)
        editor.setText(value.toString());
    if (column == 0) {
        editor.setHorizontalAlignment(SwingConstants.CENTER);
        editor.setFont(new Font("Serif", Font.BOLD, 14));
    } else {//from   w ww . jav a2  s  .c  om
        editor.setHorizontalAlignment(SwingConstants.RIGHT);
        editor.setFont(new Font("Serif", Font.ITALIC, 12));
    }
    return editor;
}

From source file:grafix.graficos.eixos.EixoHorizontalComLabels.java

public EixoHorizontalComLabels(JanelaGraficos janela) {
    super(janela);
    this.acao = janela.getAcao();
    setTickLabelFont(new Font(Font.DIALOG, Font.PLAIN, 9));
    setAutoTickUnitSelection(true);// w w w  . ja v a  2  s .  co m
}

From source file:java2d.ps.EPSColorsExample.java

/**
 * Creates an EPS file. The contents are painted using a Graphics2D
 * implementation that generates an EPS file.
 * /* w w  w  .j  a  v  a  2  s .  c  o m*/
 * @param outputFile
 *            the target file
 * @throws IOException
 *             In case of an I/O error
 */
public static void generateEPSusingJava2D(final File outputFile) throws IOException {
    OutputStream out = new java.io.FileOutputStream(outputFile);
    out = new java.io.BufferedOutputStream(out);
    try {
        // Instantiate the EPSDocumentGraphics2D instance
        final EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
        g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());

        // Set up the document size
        g2d.setupDocument(out, 400, 200); // 400pt x 200pt

        // Paint a bounding box
        g2d.drawRect(0, 0, 400, 200);

        g2d.setFont(new Font("sans-serif", Font.BOLD, 14));
        g2d.drawString("Color usage example:", 10, 20);
        g2d.setFont(new Font("sans-serif", Font.PLAIN, 12));
        g2d.drawString("RGB", 10, 84);
        g2d.drawString("CMYK", 60, 84);
        g2d.drawString("(Lab)", 110, 84);
        g2d.drawString("(Named)", 160, 84);

        // We're creating a few boxes all filled with some variant of the
        // "Postgelb" (postal yellow) color as used by Swiss Post.

        final Color colRGB = new Color(255, 204, 0);
        g2d.setColor(colRGB);
        g2d.fillRect(10, 30, 40, 40);

        // Just convert RGB to CMYK and use that
        final float[] compsRGB = colRGB.getColorComponents(null);
        final DeviceCMYKColorSpace cmykCS = ColorSpaces.getDeviceCMYKColorSpace();
        final float[] compsCMYK = cmykCS.fromRGB(compsRGB);
        final Color colCMYK = DeviceCMYKColorSpace.createCMYKColor(compsCMYK);
        g2d.setColor(colCMYK);
        g2d.fillRect(60, 30, 40, 40);

        // Try CIELab (not implemented, yet)
        final CIELabColorSpace d50 = ColorSpaces.getCIELabColorSpaceD50();
        final Color colLab = d50.toColor(83.25f, 16.45f, 96.89f, 1.0f);
        g2d.setColor(colLab);
        g2d.fillRect(110, 30, 40, 40);

        // Try named color (Separation, not implemented, yet)
        final float[] c1xyz = d50.toCIEXYZNative(83.25f, 16.45f, 96.89f);
        final NamedColorSpace postgelb = new NamedColorSpace("Postgelb", c1xyz);
        final Color colNamed = new Color(postgelb, new float[] { 1.0f }, 1.0f);
        g2d.setColor(colNamed);
        g2d.fillRect(160, 30, 40, 40);

        // Cleanup
        g2d.finish();
    } finally {
        IOUtils.closeQuietly(out);
    }
}