Search code examples
javauser-interfacejtextfieldjtextarea

Java chat client jtextfield vs jtextarea


I am writting a simple server chat client using gui to make the chat box and so on. I am simply wondering if I should use jtextarea instead of jtextfield if someone wants to write a long message since jtextfield does not allow word wrap.

Does it matter if I use jtextarea of jtextfield or is there a specific reason not to use jtextarea as my input box?


Solution

  • My guess:

    • You'll probably need both a JTextField and a JTextArea (or other multi-line text component).
    • The JTextField would be for the user to type in their chat messages to be sent. It would be editable.
    • and the JTextArea would show the incoming chats as well as the chats the user has sent. It would not be editable.
    • Consider placing the JTextArea in a JScrollPane
    • Consider placing both in a BorderLayout-using container with the JScrollPane that holds the JTextArea placed in the CENTER position and the JTextField in the SOUTH position.