Example usage for javax.swing JTextArea setLineWrap

List of usage examples for javax.swing JTextArea setLineWrap

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "should lines be wrapped")
public void setLineWrap(boolean wrap) 

Source Link

Document

Sets the line-wrapping policy of the text area.

Usage

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.
 */// ww w .ja va2 s. c  o 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.codesourcery.jasm16.ide.ui.utils.UIUtils.java

public static void showErrorDialog(Component parent, String title, String textMessage, Throwable cause) {
    final String stacktrace;
    if (cause == null) {
        stacktrace = null;//w  ww .  j av a  2s . c  om
    } else {
        final ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
        cause.printStackTrace(new PrintStream(stackTrace));
        stacktrace = new String(stackTrace.toByteArray());
    }

    final JDialog dialog = new JDialog((Window) null, title);

    dialog.setModal(true);

    final JTextArea message = createMultiLineLabel(textMessage);
    final DialogResult[] outcome = { DialogResult.CANCEL };

    final JButton okButton = new JButton("Ok");
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.YES;
            dialog.dispose();
        }
    });

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(okButton);

    final JPanel messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    cnstrs.weightx = 1;
    cnstrs.weighty = 0.1;
    cnstrs.gridheight = 1;
    messagePanel.add(message, cnstrs);

    if (stacktrace != null) {
        final JTextArea createMultiLineLabel = new JTextArea(stacktrace);

        createMultiLineLabel.setBackground(null);
        createMultiLineLabel.setEditable(false);
        createMultiLineLabel.setBorder(null);
        createMultiLineLabel.setLineWrap(false);
        createMultiLineLabel.setWrapStyleWord(false);

        final JScrollPane pane = new JScrollPane(createMultiLineLabel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        cnstrs = constraints(0, 1, true, true, GridBagConstraints.BOTH);
        cnstrs.weightx = 1.0;
        cnstrs.weighty = 0.9;
        cnstrs.gridwidth = GridBagConstraints.REMAINDER;
        cnstrs.gridheight = GridBagConstraints.REMAINDER;
        messagePanel.add(pane, cnstrs);
    }

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.BOTH);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 1.0;
    cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right           
    panel.add(messagePanel, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right      
    panel.add(buttonPanel, cnstrs);

    dialog.getContentPane().add(panel);

    dialog.setMinimumSize(new Dimension(600, 400));
    dialog.setPreferredSize(new Dimension(600, 400));
    dialog.setMaximumSize(new Dimension(600, 400));

    dialog.pack();
    dialog.setVisible(true);
}

From source file:de.ipk_gatersleben.ag_nw.graffiti.services.GUIhelper.java

public static Component getHelpTextComponent(String plainText, String title, String helpTopic) {
    JPanel result = new JPanel();
    plainText = plainText.replaceAll("<br>", "\n");
    plainText = plainText.replaceAll("<html>", "");
    plainText = plainText.replaceAll("<small>", "");
    FolderPanel fp = new FolderPanel(title, false, false, false,
            JLabelJavaHelpLink.getHelpActionListener(helpTopic));
    JTextArea helpText = new JTextArea();
    helpText.setLineWrap(true);
    helpText.setWrapStyleWord(true);//from   www.j av  a  2 s  .c o m
    helpText.setText(plainText);
    helpText.setEditable(false);
    fp.addGuiComponentRow(new JLabel(""), helpText, false);
    fp.layoutRows();
    fp.setFrameColor(Color.LIGHT_GRAY, Color.WHITE, 1, 5);

    double border = 2;
    double topBorder = 12;
    double[][] size = { { border, TableLayoutConstants.FILL, border }, // Columns
            { topBorder, TableLayoutConstants.PREFERRED, border } }; // Rows
    result.setLayout(new TableLayout(size));
    result.add(fp, "1,1");
    return result;
}

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

From source file:MainClass.java

public MainClass() {
    super("Simple SplitPane Frame");
    setSize(450, 200);/*from   w  w  w .  ja v a 2s .  com*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JTextArea jt1 = new JTextArea(sometext);
    JTextArea jt2 = new JTextArea(sometext);

    jt1.setLineWrap(true);
    jt2.setLineWrap(true);
    jt1.setMinimumSize(new Dimension(150, 150));
    jt2.setMinimumSize(new Dimension(150, 150));
    jt1.setPreferredSize(new Dimension(250, 200));
    JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jt1, jt2);
    getContentPane().add(sp, BorderLayout.CENTER);
}

From source file:ar.com.zauber.commons.spring.mail.SwingMailSender.java

/** @see SimpleMailMessage[]) */
public final void send(final SimpleMailMessage[] simpleMessages) throws MailException {
    final JTextArea area = new JTextArea(AbstractMailSender.toString(simpleMessages));
    area.setLineWrap(true);
    final JFrame frame = new JFrame("email sent");
    frame.getContentPane().add(new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
    final int frameWidth = 640;
    final int frameHeight = 480;
    frame.setPreferredSize(new Dimension(frameWidth, frameHeight));
    frame.pack();/*www .  j av  a2  s  .  c o m*/
    frame.setVisible(true);
}

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

/**
 * Creates a new panel./*from  w w w.java  2s .  c  om*/
 *
 * @param text  the component containing the text.
 */
public DescriptionPanel(final JTextArea text) {

    setLayout(new BorderLayout());
    text.setLineWrap(true);
    text.setWrapStyleWord(true);
    add(new JScrollPane(text, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));

}

From source file:net.sf.firemox.ui.wizard.AboutMdb.java

/**
 * Creates a new instance of AboutMdb <br>
 * // w  ww  . j a  v a2  s .  co m
 * @param parent
 */
public AboutMdb(JFrame parent) {
    super(LanguageManager.getString("about.tbs"),
            "<html><b>" + LanguageManager.getString("tbsname") + ": </b>" + MdbLoader.getTbsFullName()
                    + "<br><b>" + LanguageManager.getString("author") + ": </b>" + MdbLoader.getAuthor()
                    + "<br><b>" + LanguageManager.getString("info") + ": </b>" + MdbLoader.getMoreInfo()
                    + "<br><b>" + LanguageManager.getString("version") + ": </b>" + MdbLoader.getVersion(),
            "mp64.gif", LanguageManager.getString("close"), 420, 320);
    JTextArea disclaimer = new JTextArea();
    disclaimer.setEditable(false);
    disclaimer.setLineWrap(true);
    disclaimer.setWrapStyleWord(true);
    disclaimer.setAutoscrolls(true);
    // Then try and read it locally
    final InputStream inGPL = MToolKit.getResourceAsStream(MToolKit.mdbFile);
    if (inGPL != null) {
        disclaimer.setText(MdbLoader.getDisclaimer().replaceAll("\t", "").replaceAll("\n", ""));
        IOUtils.closeQuietly(inGPL);
    }
    JScrollPane disclaimerSPanel = new JScrollPane();
    disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    MToolKit.addOverlay(disclaimerSPanel);
    disclaimerSPanel.setViewportView(disclaimer);
    gameParamPanel.add(disclaimerSPanel);
    setLocation((getToolkit().getScreenSize().width - 420) / 2,
            (getToolkit().getScreenSize().height - 320) / 2);
}

From source file:net.sf.firemox.deckbuilder.DeckRules.java

/**
 * Create a new instance of DeckRules/*  ww  w.  j  av  a  2  s  .  c  o  m*/
 * 
 * @param parent
 */
public DeckRules(JFrame parent) {
    super(LanguageManager.getString("jdeckrules", MdbLoader.getTbsFullName()),
            LanguageManager.getString("jdeckrules.tooltip", MdbLoader.getTbsFullName()), "wiz_library_wiz.png",
            LanguageManager.getString("close"), 490, 300);
    // ... Set initial text, scrolling, and border.
    final JTextArea textRules = new JTextArea();
    textRules.setEditable(false);
    textRules.setLineWrap(true);
    textRules.setWrapStyleWord(true);
    textRules.setAutoscrolls(true);
    textRules.setTabSize(2);
    textRules.setText("No defined rules");
    BufferedReader inGPL = null;
    try {
        inGPL = new BufferedReader(new FileReader(MToolKit.getTbsFile(
                "decks/DECK_CONSTRAINTS-" + LanguageManager.getLanguage().getLocale() + "-lang.info")));
        textRules.read(inGPL, "Deck constraints");
    } catch (IOException e) {
        // Ignore this error
    } finally {
        IOUtils.closeQuietly(inGPL);
    }

    final JScrollPane scrollingArea = new JScrollPane(textRules);
    gameParamPanel.add(scrollingArea);
    pack();
}

From source file:Main.java

protected JTextComponent createTextComponent() {
    JTextArea ta = new JTextArea();
    ta.setLineWrap(true);
    return ta;
}