Example usage for javax.swing UIManager getFont

List of usage examples for javax.swing UIManager getFont

Introduction

In this page you can find the example usage for javax.swing UIManager getFont.

Prototype

public static Font getFont(Object key) 

Source Link

Document

Returns a font from the defaults.

Usage

From source file:Main.java

/**
 * Configures a text area to display as if it were a label.  This can be useful if you know how many columns
 * you want a label to be.//from   w w  w . j a  v  a 2  s  . c o  m
 * @param textArea The text area to configure as a JLabel.
 */
public static void configureAsLabel(JTextArea textArea) {
    textArea.setOpaque(false);
    Font textFont = UIManager.getFont("Label.font");
    textArea.setFont(textFont);
    textArea.setBorder(null);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setEditable(false);
}

From source file:Main.java

/**
 * Returns the bounds of the given string.
 *
 * @param text the string to measure//from www .  j  a v  a2s  .  com
 * @return the bounds of the given string
 */
public static Rectangle2D getDefaultStringSize(String text) {
    Font font = UIManager.getFont("Label.font");
    FontRenderContext frc = new FontRenderContext(null, true, false);
    TextLayout layout = new TextLayout(text, font, frc);

    return layout.getBounds();
}

From source file:Main.java

/**
 * Gets the text width./* ww  w. j  av a2 s .co m*/
 *
 * @param text
 *            the text
 * @param bold
 *            the bold
 * @return the text width
 */
public static int getTextWidth(final String text, final boolean bold) {
    Font font = UIManager.getFont("Label.font");
    if (bold) {
        font = font.deriveFont(Font.BOLD);
    }
    return getTextWidth(text, font);
}

From source file:Main.java

/**
 * Returns the string width for the default label font and string.
 * /*from  ww w.  j ava  2s.  co m*/
 * @param aString
 *          the string to get the width for.
 * @return a string width, >= 0.
 */
public static int getStringWidth(final String aString) {
    return getStringWidth(UIManager.getFont(SWING_LABEL_FONT), aString);
}

From source file:de.aidger.view.utils.Charts.java

/**
 * Creates a 3D pie chart./*  w  w w.j  a  v a 2  s  . c o m*/
 * 
 * @param title
 *            the diagram title
 * @param dataset
 *            the dataset.
 * @param width
 *            the width of the chart as image
 * @param height
 *            the height of the chart as image
 * 
 * @return the 3D pie chart as image
 */
public static ImageIcon createPieChart3D(String title, PieDataset dataset, int width, int height) {
    JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false);

    Font titleFont = UIManager.getFont("TitledBorder.font");

    chart.setBackgroundPaint(null);
    chart.getLegend().setBackgroundPaint(null);
    chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14));
    chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor"));
    chart.setBorderPaint(null);
    chart.getLegend().setBorder(0, 0, 0, 0);

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);
    plot.setForegroundAlpha(0.9f);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setNoDataMessage(_("No data to display."));
    plot.setLabelGenerator(null);
    plot.setInsets(new RectangleInsets(10, 1, 5, 1));
    plot.setBackgroundPaint(null);
    plot.setOutlineVisible(false);
    plot.setDarkerSides(true);

    return new ImageIcon(chart.createBufferedImage(width, height));
}

From source file:com.samebug.clients.idea.ui.component.ExceptionMessageLabel.java

public ExceptionMessageLabel(@Nullable String message) {
    {//from  ww  w.j a  va 2 s  . co  m
        final String escapedText;
        if (message == null) {
            escapedText = String.format("<html><i>%s</i></html>",
                    SamebugBundle.message("samebug.exception.noMessage"));
        } else {
            // Escape html, but keep line breaks
            String broken = StringEscapeUtils.escapeHtml(message).replaceAll("\\n", "<br>");
            escapedText = String.format("<html>%s</html>", broken);
        }

        setFont(UIManager.getFont("TextArea.font"));
        setText(escapedText);
        setVerticalAlignment(SwingConstants.TOP);
    }

}

From source file:au.org.ala.delta.ui.TextFileViewer.java

public TextFileViewer(Window owner, File file) throws IOException {
    super(owner);
    setModal(true);/* w  ww. ja  v  a 2s .  c om*/
    getContentPane().setLayout(new BorderLayout());
    viewer = new JTextPane();

    viewer.setEditable(false);
    viewer.setBackground(Color.WHITE);
    viewer.setBorder(null);
    viewer.setOpaque(true);
    viewer.setFont(UIManager.getFont("Label.font"));

    JScrollPane scroller = new JScrollPane(viewer);
    getContentPane().add(scroller, BorderLayout.CENTER);

    setTitle(file.getAbsolutePath());
    displayFileContents(file);
    pack();
}

From source file:au.org.ala.delta.ui.MessageDialogHelper.java

/**
 * Creates a text area that looks like a JLabel that has a preferredSize calculated to fit
 * all of the supplied text wrapped at the supplied column. 
 * @param text the text to display in the JTextArea.
 * @param numColumns the column number to wrap text at.
 * @return a new JTextArea configured for the supplied text.
 *///  w  w  w.ja  v a2s .co m
private static JTextArea createMessageDisplay(String text, int numColumns) {
    JTextArea textArea = new JTextArea();
    textArea.setEditable(false);

    textArea.setBackground(UIManager.getColor("Label.background"));
    textArea.setFont(UIManager.getFont("Label.font"));

    textArea.setWrapStyleWord(true);
    textArea.setLineWrap(true);
    textArea.setColumns(numColumns);

    String wrapped = WordUtils.wrap(text, numColumns);
    textArea.setRows(wrapped.split("\n").length - 1);

    textArea.setText(text);

    // Need to set a preferred size so that under OpenJDK-6 on Linux the JOptionPanes get reasonable bounds 
    textArea.setPreferredSize(new Dimension(0, 0));

    return textArea;

}

From source file:de.aidger.view.utils.Charts.java

/**
 * Creates a xy area chart./*  w  w  w .ja  va 2s .co  m*/
 * 
 * @param title
 *            the diagram title
 * @param dataset
 *            the dataset.
 * @param width
 *            the width of the chart as image
 * @param height
 *            the height of the chart as image
 * @return the xy area chart as image
 */
public static ImageIcon createXYAreaChart(String title, XYDataset dataset, int width, int height) {
    JFreeChart chart = ChartFactory.createXYAreaChart(title, "", "", dataset, PlotOrientation.VERTICAL, false,
            false, false);

    Font titleFont = UIManager.getFont("TitledBorder.font");

    chart.setBackgroundPaint(null);
    chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14));
    chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor"));
    chart.setBorderPaint(null);

    XYPlot plot = chart.getXYPlot();
    plot.setInsets(new RectangleInsets(10, 1, 5, 1));
    plot.setBackgroundPaint(null);
    plot.setOutlineVisible(false);
    plot.setNoDataMessage(_("No data to display."));

    ValueAxis domainAxis = new DateAxis();
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setTickLabelFont(UIManager.getFont("RootPane.font"));

    ValueAxis rangeAxis = new NumberAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    plot.setDomainAxis(domainAxis);
    plot.setRangeAxis(rangeAxis);

    plot.setForegroundAlpha(0.5f);

    return new ImageIcon(chart.createBufferedImage(width, height));
}

From source file:CheckBoxNodeTreeSample.java

public CheckBoxNodeRenderer() {
    Font fontValue;/*w w  w  .  j  a v  a2 s  . co  m*/
    fontValue = UIManager.getFont("Tree.font");
    if (fontValue != null) {
        leafRenderer.setFont(fontValue);
    }
    Boolean booleanValue = (Boolean) UIManager.get("Tree.drawsFocusBorderAroundIcon");
    leafRenderer.setFocusPainted((booleanValue != null) && (booleanValue.booleanValue()));

    selectionBorderColor = UIManager.getColor("Tree.selectionBorderColor");
    selectionForeground = UIManager.getColor("Tree.selectionForeground");
    selectionBackground = UIManager.getColor("Tree.selectionBackground");
    textForeground = UIManager.getColor("Tree.textForeground");
    textBackground = UIManager.getColor("Tree.textBackground");
}