Ayuda con jpanel
Publicado por Marcos (35 intervenciones) el 22/02/2021 19:10:06
Hola, buenas tardes.
Tengo un problema con Jpanel, tengo dos jpanel, al querer mostrar el segundo jpanel no sale ninguno de los componentes que tiene dentro. Nose cual podria ser el problema ya que soy novato trabajando con GUI.
Este es el codigo:
contentPane es el primer panel y panel el segundo, no me muestra el contenido de panel.
De verdad agradeceria que alguien pueda ayudarme
Tengo un problema con Jpanel, tengo dos jpanel, al querer mostrar el segundo jpanel no sale ninguno de los componentes que tiene dentro. Nose cual podria ser el problema ya que soy novato trabajando con GUI.
Este es el codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
public class Clase1 extends JFrame implements ActionListener {
private JPanel contentPane;
private JTextField txtAgregarJugador;
private JButton boton1;
private JPanel panel;
static ArrayList<String> vectorNombres = new ArrayList<String>();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Clase1 frame = new Clase1();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Clase1() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(200, 200, 634, 460);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
//contentPane.setBackground(Color.green);
setContentPane(contentPane);
JTextField txtAgregarJugador = new JTextField();
//txtAgregarJugador.setBounds(new Rectangle(0, 0, 25, 23));
//txtAgregarJugador.setEditable(true);
txtAgregarJugador.setBounds(122, 28, 179, 33);
txtAgregarJugador.setHorizontalAlignment(SwingConstants.CENTER);
txtAgregarJugador.setBackground(new Color(192, 192, 192));
//txtAgregarJugador.setEnabled(false);
txtAgregarJugador.setFont(new Font("Arial", Font.ITALIC, 13));
txtAgregarJugador.setText("Nombre jugador");
txtAgregarJugador.setToolTipText("Agregar jugador");
txtAgregarJugador.setColumns(10);
boton1 = new JButton("Agregar jugador");
boton1.setForeground(new Color(255, 0, 255));
boton1.setBackground(new Color(218, 112, 214));
boton1.setBounds(new Rectangle(122, 85, 179, 31));
boton1.setFont(new Font("Trebuchet MS", Font.PLAIN, 11));
contentPane.setLayout(null);
contentPane.add(txtAgregarJugador);
contentPane.add(boton1);
JTextArea textArea = new JTextArea();
textArea.setBackground(Color.RED);
//textArea.setForeground(new Color(255, 105, 180));
textArea.setToolTipText("mostrarJugadores");
textArea.setBounds(150, 130, 100, 100);
contentPane.add(textArea);
JButton boton2 = new JButton("Iniciar juego");
boton2.setBackground(new Color(255, 0, 255));
//boton2.setForeground(new Color(255, 0, 255));
boton2.setBounds(318, 219, 108, 33);
contentPane.add(boton2);
boton2.addActionListener(this);
panel = new JPanel();
//panel.setBounds(0, 0, 436, 252);
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
panel.setBackground(Color.RED);
JButton boton3 = new JButton("Panel2");
boton3.setBounds(new Rectangle(122, 85, 179, 31));
boton3.setBackground(new Color(255, 0, 255));
panel.add(boton3);
contentPane.setVisible(true);
panel.setVisible(false);
}
public void actionPerformed(ActionEvent e) {
contentPane.setVisible(false);
panel.setVisible(true);
};
}
contentPane es el primer panel y panel el segundo, no me muestra el contenido de panel.
De verdad agradeceria que alguien pueda ayudarme
Valora esta pregunta


0