Here you can find the source of getMessageScrollPane(String message)
private static JScrollPane getMessageScrollPane(String message)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); you may import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; public class Main { private static JScrollPane getMessageScrollPane(String message) { JTextArea ta = new JTextArea(message); ta.setBorder(new EmptyBorder(0, 0, 0, 0)); ta.setLineWrap(true);/*w ww.j a va 2 s. c om*/ ta.setWrapStyleWord(true); ta.setCaretPosition(0); ta.setEditable(false); JScrollPane sp = new JScrollPane(ta); sp.setBorder(new EmptyBorder(5, 5, 5, 5)); if (message.length() < 100) { sp.setPreferredSize(new Dimension(400, 50)); } else { sp.setPreferredSize(new Dimension(400, 100)); } return sp; } }