Using Google or your favorite search engine, search for information on how to us
ID: 3771686 • Letter: U
Question
Using Google or your favorite search engine, search for information on how to use a JTextArea, its constructors, and its setText() and append() methods. Write a Java application that allows the user to select options for a dormitory room. Use JCheckBoxes for options such as private room, Internet connection, Cable TV connection, microwave, refrigerator, and so on. When the application starts, use a text area to display a message listing the options that are not yet selected. As the user selects and deselects options, add appropriate messages to the common text area so it accumulates a running list that reflects the user's choices.
Explanation / Answer
The JTextArea class provides a component that displays multiple lines of text and optionally allows the user to edit the text. If you need to obtain only one line of input from the user, you should use a text field. If you want the text area to display its text using multiple fonts or other styles, you should use an editor pane or text pane. If the displayed text has a limited length and is never edited by the user, use a label.
constructors
JTextArea()
Constructs a new TextArea.
Constructs a new JTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0).
Constructs a new JTextArea with the specified number of rows and columns, and the given model.
Constructs a new empty TextArea with the specified number of rows and columns.
Constructs a new TextArea with the specified text displayed.
Constructs a new TextArea with the specified text and number of rows and columns.
Settext():
void setText(String):sets or obtains the text displayed by the text area.
To append text to the end of the JTextArea document we can use theappend(String str) method. This method does nothing if the document is null or the string is null or empty.
constructors
JTextArea()
Constructs a new TextArea.
JTextArea(Document doc)Constructs a new JTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0).
JTextArea(Document doc, String text, int rows, int columns)Constructs a new JTextArea with the specified number of rows and columns, and the given model.
JTextArea(int rows, int columns)Constructs a new empty TextArea with the specified number of rows and columns.
JTextArea(String text)Constructs a new TextArea with the specified text displayed.
JTextArea(String text, int rows, int columns)Constructs a new TextArea with the specified text and number of rows and columns.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.