Example usage for javax.swing JTextPane getBorder

List of usage examples for javax.swing JTextPane getBorder

Introduction

In this page you can find the example usage for javax.swing JTextPane getBorder.

Prototype

public Border getBorder() 

Source Link

Document

Returns the border of this component or null if no border is currently set.

Usage

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a text pane to the parent container
 * /* w w  w  . jav a2  s .c  o  m*/
 * @param container - parent container
 * @param text - text for new Text Pane
 * @param placement - TableLayout placement within the parent container
 * @param debug - turn on/off red debug borders
 * @return new JTextPane
 */
public static synchronized JTextPane addTextPane(Container container, String text, String placement,
        boolean debug) {
    StyleContext context = new StyleContext();
    StyledDocument document = new DefaultStyledDocument(context);

    Style style = context.getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT);

    try {
        document.insertString(document.getLength(), text, null);
    } catch (BadLocationException e) {
        log.error("BadLocationException inserting text to document.");
    }

    JTextPane textPane = new JTextPane(document);
    textPane.setOpaque(false);
    textPane.setEditable(false);
    textPane.setFocusable(false);
    container.add(textPane, placement);

    if (debug == true)
        textPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                textPane.getBorder()));

    return textPane;
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * A version of addTextPane that lets you add a style and context
 * //from w  w  w  .  j a  v  a2  s  .  c  om
 * @param container - parent container
 * @param text - text for new Text Pane
 * @param placement - TableLayout placement within the parent container
 * @param context - context for new text pane
 * @param style - style to apply to new text pane
 * @param debug - turn on/off red debug borders
 * @return new JTextPane
 */
public static synchronized JTextPane addTextPane(Container container, String text, String placement,
        StyleContext context, Style style, boolean debug) {
    StyledDocument document = new DefaultStyledDocument(context);

    try {
        document.insertString(document.getLength(), text, style);
    } catch (BadLocationException e) {
        log.error("BadLocationException inserting text to document.");
    }

    JTextPane textPane = new JTextPane(document);
    textPane.setOpaque(false);
    textPane.setEditable(false);
    textPane.setFocusable(false);
    container.add(textPane, placement);

    if (debug == true)
        textPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                textPane.getBorder()));

    return textPane;
}