jtextarea in java
JTextArea
is a Swing component in Java that allows for the display and editing of multiple lines of text. It can be used to implement text areas or text editors in a graphical user interface (GUI).
Here is a simple example of how to create a JTextArea
in Java:
import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextArea; public class MyTextArea extends JFrame { private JTextArea textArea; public MyTextArea() { super("My First JTextArea"); textArea = new JTextArea(10, 40); JScrollPane scrollPane = new JScrollPane(textArea); add(scrollPane); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true); } public static void main(String[] args) { MyTextArea frame = new MyTextArea(); } }w:ecruoSww.theitroad.com
In this example, we create a new class that extends the JFrame
class. We create a new instance of the JTextArea
class, and add it to a JScrollPane
to provide scrollbars when the text area content exceeds the visible area. We then add the scroll pane to the frame, and set the default close operation of the window. We also call pack()
to ensure the frame is sized to its preferred size, and set it to be visible.
When you run this code, a new window will appear with a text area inside of it. The text area will be 10 rows by 40 columns. You can enter and edit text in the text area using your keyboard. The scrollbars will appear automatically when the text area content exceeds the visible area.