Eventuali duplicati:
Java GUI repaint() problem?repaint() in Java
ho scrivere un codice Java, ma ho un problema con il problema GUI. Quando aggiungo un componente nell'oggetto JFrame, allora chiamo il metodo repaint() per aggiornare la GUI, ma non funziona. Ma quando minimizzo o ridimensiono questo frame, la GUI viene aggiornata.
Ecco il mio codice:
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(460, 500);
frame.setTitle("Circles generator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
String input = JOptionPane.showInputDialog("Enter n:");
int n = Integer.parseInt(input);
CircleComponent component = new CircleComponent(n);
frame.add(component);
component.repaint();
}
try 'frame.repaint();'? – Sheriff