When I want to add a label to the Panel, it will not appear until resizing the frame. It does not update.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Actions_GUI
{
JFrame frame;
JPanel panel;
JButton button;
JLabel label;
Actions_GUI()
{
frame = new JFrame();
frame.setSize(400,300);
frame.setTitle("WHY ?");
panel = new JPanel();
panel.setBackground(Color.black);
button = new JButton(" WHY ?");
Here's the event for creating a label on the main panel.
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
label=new JLabel(" Why Don't Upadate? ");
label.setForeground(Color.magenta);
panel.add(label);
}
});
panel.add(button);
frame.add(panel);
frame.setVisible(true);
}
public static void main(String [] args)
{
Actions_GUI object = new Actions_GUI();
}
}