Advertisement
fabioceep

JAVA: Exemplo de JTextArea (PG 293)

Feb 23rd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. package textarea1;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. public class TextArea1 implements ActionListener{
  8.     JTextArea texto;
  9.     public static void main(String[] args) {
  10.         TextArea1 sistema = new TextArea1();
  11.         sistema.iniciar();
  12.     }
  13.     public void iniciar(){
  14.         JFrame janela = new JFrame();
  15.         JPanel painel = new JPanel();
  16.         JButton botao = new JButton("Clique aqui");
  17.         botao.addActionListener(this);
  18.        
  19.         texto = new JTextArea(10,20);
  20.         texto.setLineWrap(true);
  21.        
  22.         JScrollPane barraDeRolagem = new JScrollPane(texto);
  23.         barraDeRolagem.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
  24.         barraDeRolagem.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  25.        
  26.         painel.add(barraDeRolagem);
  27.         janela.getContentPane().add(BorderLayout.CENTER, painel);
  28.         janela.getContentPane().add(BorderLayout.SOUTH,botao);
  29.         janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30.        
  31.         janela.setSize(350,300);
  32.         janela.setVisible(true);
  33.     }
  34.  
  35.     @Override
  36.     public void actionPerformed(ActionEvent e) {
  37.         texto.append("Estou escrevendo \n");
  38.     }
  39.    
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement