I'm trying to create a project where I print multiple phrases in a JTextArea
, but for this, I need to include a JScrollPane
. I looked at some examples on the internet but none are working.
public class Projeto extends JFrame {
JPanel painel = new JPanel();
public static JTextArea textarea = new JTextArea();
public static JScrollPane sp = new JScrollPane();
JButton cmd1;
public static void main(String[] args) {
new Projeto();
}
public Projeto(){
super("Árvore");
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
painel.setPreferredSize(new Dimension(600,400));
painel.setLayout(null);
cmd1 = new JButton("Start!");
cmd1.setBounds(450, 50, 100, 30);
painel.add(cmd1);
textarea.setBounds(50, 50, 300, 300);
textarea.setEditable(true);
sp.add(textarea);
painel.add(sp);
add(painel);
pack();
setVisible(true);
event e = new event();
cmd1.addActionListener(e);
}
public static void atualiza(String frase){
textarea.append(frase);
}
public class event implements ActionListener{
Pai p = new Pai();
public void actionPerformed(ActionEvent e){
p.start();
}
}
}