Example usage for javax.swing JTextArea setFont

List of usage examples for javax.swing JTextArea setFont

Introduction

In this page you can find the example usage for javax.swing JTextArea setFont.

Prototype

public void setFont(Font f) 

Source Link

Document

Sets the current font.

Usage

From source file:Main.java

public static void main(String args[]) {
    JTextArea textArea = new JTextArea();

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    DefaultCaret caret = new DefaultCaret() {
        @Override//from w w  w.j  a va2 s.com
        public boolean isSelectionVisible() {
            return true;
        }
    };
    textArea.setCaret(caret);
    textArea.setFont(new java.awt.Font("Miriam Fixed", 0, 13));

    Color color = Color.BLUE;
    // textArea.setBackground(color);
    textArea.setSelectedTextColor(color);
    f.getContentPane().add(new JScrollPane(textArea));
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void changeFontSize(JTextArea textArea, int newSize) {
    textArea.setFont(textArea.getFont().deriveFont((float) newSize));
}

From source file:Main.java

public static void copyFontAndMargins(final JTextArea target, final JComponent source) {
    final Insets insets = source.getInsets();
    target.setFont(source.getFont());
    target.setMargin(insets);/*from  w  w  w.  j a v a2  s .c om*/
}

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 a2  s . c om*/
 * @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: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 .  j  a va 2  s. 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:Main.java

public static JScrollPane createScrollPane(JTextArea textArea, Font font, Color bgColor) {
    JScrollPane scrollPane = new JScrollPane(textArea);
    textArea.setLineWrap(true);// ww w  . j a v  a2 s .  c o  m
    textArea.setWrapStyleWord(true);
    if (null != font) {
        textArea.setFont(font);
    }
    textArea.setOpaque(true);
    if (bgColor != null) {
        textArea.setBackground(bgColor);
    }

    return scrollPane;
}

From source file:com.clank.launcher.swing.SwingHelper.java

/**
 * Show a message dialog using/*ww  w  . j a  va 2s.co  m*/
 * {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)}.
 *
 * <p>The dialog will be shown from the Event Dispatch Thread, regardless of the
 * thread it is called from. In either case, the method will block until the
 * user has closed the dialog (or dialog creation fails for whatever reason).</p>
 *
 * @param parentComponent the frame from which the dialog is displayed, otherwise
 *                        null to use the default frame
 * @param message the message to display
 * @param title the title string for the dialog
 * @param messageType see {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)}
 *                    for available message types
 */
public static void showMessageDialog(final Component parentComponent, @NonNull final String message,
        @NonNull final String title, final String detailsText, final int messageType) {

    if (SwingUtilities.isEventDispatchThread()) {
        // To force the label to wrap, convert the message to broken HTML
        String htmlMessage = "<html><div style=\"width: 250px\">" + htmlEscape(message);

        JPanel panel = new JPanel(new BorderLayout(0, detailsText != null ? 20 : 0));

        // Add the main message
        panel.add(new JLabel(htmlMessage), BorderLayout.NORTH);

        // Add the extra details
        if (detailsText != null) {
            JTextArea textArea = new JTextArea(_("errors.reportErrorPreface") + detailsText);
            JLabel tempLabel = new JLabel();
            textArea.setFont(tempLabel.getFont());
            textArea.setBackground(tempLabel.getBackground());
            textArea.setTabSize(2);
            textArea.setEditable(false);
            textArea.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE);

            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(350, 120));
            panel.add(scrollPane, BorderLayout.CENTER);
        }

        JOptionPane.showMessageDialog(parentComponent, panel, title, messageType);
    } else {
        // Call method again from the Event Dispatch Thread
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    showMessageDialog(parentComponent, message, title, detailsText, messageType);
                }
            });
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}

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 .ja v a2  s.c  om*/
}

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);
    area.setLineWrap(true);//from   w  ww.j a v  a  2s  . c  o m
    JScrollPane scrollpane = new JScrollPane(area);
    add(scrollpane);
}

From source file:JTextAreaDemo.java

public JTextAreaDemo() {
    super("JTextAreaDemo");
    GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font font = new Font("LucidaSans", Font.PLAIN, 40);
    JTextArea textArea = new JTextArea(davidMessage + andyMessage);
    textArea.setFont(font);
    this.getContentPane().add(textArea);
    textArea.show();//from  w w  w  . j  a  v  a  2 s  .c o  m
}