As I already wrote in the title of the question, I am trying to make a JPanel appear with a built-in JTextArea and that in turn this JTextArea write what is in another JPanel. The Jpanel are in different classes. (Below, leave a picture of the interface) I tried everything I'm going crazy hehehehehehe. Then I leave the code of the two JPanel, sorry for the length of the code. I thank you in advance for your answer.
Greetings
package interfaz;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.TitledBorder;
public class Panel1 extends JPanel implements ActionListener{
// atributos
private JLabel labelSeccion;
private JTextField textSeccion;
private JLabel labelProducto;
private JTextField textProducto;
//private JLabel labelCantidad;
//private JTextField textCantidad;
private JLabel labelFecha;
private JTextField textFecha;
//private JLabel labelImagen;
private JButton botonIngresar;
private JTextField textCodigo;
private JComboBox listado;
private JLabel labelCodigo;
private String seccionEscrita;
private String productoEscrito;
private String fechaEscrita;
private String codigoEscrito;
//private JLabel labelVacio;
public Panel1(String f){
}
public Panel1(){
setLayout(new BorderLayout());
TitledBorder borde=BorderFactory.createTitledBorder("datos de panel 1");
borde.setTitleColor(Color.BLUE);
setBorder(borde);
Color rgb=new Color(66,244,226);
JPanel datos = new JPanel();
labelSeccion=new JLabel("Sección: ");
labelProducto=new JLabel("Producto: ");
//labelCantidad=new JLabel("Cantidad: ");
labelFecha = new JLabel("Fecha");
labelCodigo= new JLabel("Codigo");
textSeccion= new JTextField(20);
textSeccion.setEditable(false);
textSeccion.setBackground(rgb);
textSeccion.setForeground(Color.BLUE);
textProducto= new JTextField(20);
textProducto.setEditable(true);
textProducto.setBackground(rgb);
textProducto.setForeground(Color.BLUE);
//textCantidad= new JTextField(20);
//textCantidad.setEditable(true);
//textCantidad.setBackground(rgb);
//textCantidad.setForeground(Color.BLUE);
textFecha= new JTextField(20);
textFecha.setEditable(true);
textFecha.setBackground(rgb);
textFecha.setForeground(Color.BLUE);
textCodigo= new JTextField(20);
textCodigo.setEditable(true);
textCodigo.setBackground(rgb);
textCodigo.setForeground(Color.BLUE);
botonIngresar = new JButton("ingresar datos: ");
datos.setLayout(new GridLayout(5,2));
datos.add(labelSeccion);
datos.add(textSeccion);
datos.add(labelProducto);
datos.add(textProducto);
datos.add(labelFecha);
datos.add(textFecha);
datos.add(labelCodigo);
datos.add(textCodigo);
datos.add(botonIngresar);
JPanel listaCombo = new JPanel();
listado=new JComboBox();
listado.addItem("Administracion");
listado.addItem("RRHH");
listado.addItem("Bodega");
listado.addActionListener(this);
listaCombo.add(listado);
add(datos,BorderLayout.WEST);
add(listaCombo,BorderLayout.CENTER);
botonIngresar.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
Object botonPulsado = e.getSource();
if(botonPulsado==listado){
textSeccion.setText((String)listado.getSelectedItem());
}
else{
seccionEscrita=textSeccion.getText();
productoEscrito=textProducto.getText();
fechaEscrita=textFecha.getText();
codigoEscrito=textCodigo.getText();
try{
EscribirArchivo archivo = new EscribirArchivo(seccionEscrita,
productoEscrito,fechaEscrita,codigoEscrito);
}catch(Exception exception){
System.out.println(" ");
}
textSeccion.setText("");
textProducto.setText("");
textFecha.setText("");
textCodigo.setText("");
}
}
// getter
public String darSeccion(){
return seccionEscrita;
}
public String darProducto(){
return productoEscrito;
}
public String darFecha(){
return fechaEscrita;
}
}
Now I leave you the code of the panel that I want to appear.
package interfaz;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Panel2 extends JPanel implements ActionListener{
private JTextArea cuadro;
private JPanel panel;
private JPanel tabla;
private String seccion;
private String producto;
private String fecha;
private JButton boton;
public Panel2(){
setLayout(new BorderLayout());
TitledBorder borde=BorderFactory.createTitledBorder("datos de panel 2");
borde.setTitleColor(Color.BLUE);
setBorder(borde);
JPanel panel=new JPanel();
//tabla.add(cuadro);
//add(tabla,BorderLayout.CENTER);
//add(tabla);
//Panel1 texto = new Panel1(" ");
tabla=new JPanel();
//tabla.setVisible(false);
cuadro= new JTextArea(10,30);
//cuadro.setSize(30, 50);
cuadro.setVisible(true);
//cuadro.setBounds(100,200);
JScrollPane JS = new JScrollPane(cuadro);
cuadro.append(seccion);
cuadro.append("\r\n");
cuadro.append(producto);
cuadro.append("\r\n");
cuadro.append(fecha);
cuadro.append("\r\n");
tabla.add(JS);
// add(tabla);
panel.add(tabla);
add(panel,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e){
}
public void setSeccion(String seccion){
this.seccion=seccion;
}
public void setProducto(String producto){
this.producto=producto;
}
public void setFecha(String fecha){
this.fecha=fecha;
}
}