1. JTextArea messages = new JTextArea(5, 30); 2. JScrollPane scrollTextBox = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ); 3. Container window; 4. ... 5. messages.setPreferredSize(new Dimension(500,100)); 6. messages.setLineWrap(true); 7. messages.add(scrollTextBox, BorderLayout.CENTER); 8. window.add(messages); 9.
10. I'm trying to write a text box within a GUI box that returns messages from a server, it needs a scroll bar because messages are continually being sent but at the moment only the first few lines are visible and the rest aren't because i can't get the scroll to work. 11. my attempts before have either resulted in this error: 12. java.lang.IllegalArgumentException: adding container's parent to itself 13. at java.awt.Container.checkAddToSelf(Unknown Source) 14. at java.awt.Container.addImpl(Unknown Source) 15. at java.awt.Container.add(Unknown Source) 16. at LODGUI.drawAndShow(LODGUI.java:91) 17. at LODClient.run(LODClient.java:94) 18. at LODClient.main(LODClient.java:157) 19.
20. or no change and no scroll bar.