Home / ພື້ນຖານ Desktop app / GUI_Component / JTextArea
Java Text Area (JTextArea) - Swing Example ສຳລັບ Text Area ຫຼື JTextArea (javax.swing.JTextArea) ຈັດຢູ່ໃນກຸ່ມຂອງ Component ໃຊ້ເປັນ Input ແບບ Multiple Line ທີ່ຮອງຮັບຮູບແບບຂໍ້ຄວາມທີ່ມີຂະໜາດໃຫຍ່ ແລະ ປະລິມານຫລາຍ ສາມາດກຳນົດຄວາມສູວຂອງກລ່ອງຮັບຂໍ້ມູນແລະສາມາດພິມຂໍ້ຄວາມໄດ້ຫຼາຍບັນທັດ ໂດຍທີ່ JTextArea ມີ Property ທີ່ສຳຄັນ ໆ ຢູ່ 2 ຕົວຄື getText() ແລະ setText() ໃຊ້ສຳລັບ get ຄ່າ ແລະ set ຄ່າ
public class MyForm extends JFrame {
public MyForm() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 362, 249);
setTitle("Kittisay java");
setLayout(null);
// TextArea
final JTextArea textArea = new JTextArea();
textArea.setBounds(76, 11, 191, 50);
add(textArea);
// Label
final JLabel lbl = new JLabel("Result");
lbl.setBounds(103, 120, 144, 14);
add(lbl);
// Button
JButton btn1 = new JButton("Button 1");
btn1.addActionListener((e) -> {
lbl.setText("Hello : " + textArea.getText());
});
btn1.setBounds(128, 72, 99, 23);
add(btn1);
}
public static void main(String[] args) {
MyForm frm = new MyForm();
frm.setVisible(true);
}
public class MyForm extends JFrame {
public MyForm() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 362, 249);
setTitle("Kittisay Java");
setLayout(null);
// TextArea
JTextArea textArea = new JTextArea();
// ScrollPane
JScrollPane scroll = new JScrollPane(textArea);
scroll.setBounds(100, 52, 130, 50);
add(scroll);
// Label
JLabel lbl = new JLabel("Result");
lbl.setBounds(107, 170, 144, 14);
add(lbl);
// Button
JButton btn1 = new JButton("Button 1");
btn1.addActionListener((e) -> {
lbl.setText("Hello : " + textArea.getText());
});
btn1.setBounds(119, 129, 99, 23);
add(btn1);
}
public static void main(String[] args) {
MyForm frm = new MyForm();
frm.setVisible(true);
}