JTextArea has a rather specific side effect, in the right conditions it can grow on its own. I accidentally stumbled upon this by accident when I tried to create a simple two-line text editor (the length of limited characters per line, a maximum of two lines) ...
In principle, given the correct layout manager, this component can grow on its own - in fact, it makes sense, but it took me by surprise ...


Now you can use the ComponentListener to monitor when a component changes size if it interests you ...
public class TestTextArea extends JFrame { public TestTextArea() { setLayout(new GridBagLayout()); JTextArea textArea = new JTextArea(); textArea.setColumns(10); textArea.setRows(1); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); add(textArea); setSize(200, 200); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); textArea.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent ce) { System.out.println("I've changed size"); } }); } public static void main(String[] args) { new TestTextArea(); } }
source share