Hello, I wanna create a timer in Java, starting with the run button and the label of the time, but when I press the button, the label gets the size of the window, and I don't know why, what's wrong? (I wanted upload captures, but I couldn't for some reason).
import javax.swing.*; import java.awt.*; public class Temporizador extends JFrame { private final JLabel tiempo; private final JButton iniciar; public static void main(String[] args) { new Temporizador(); } public Temporizador() { setTitle("Temporizador"); setSize(800, 600); setDefaultCloseOperation(EXIT_ON_CLOSE); setResizable(false); setLocationRelativeTo(null); setVisible(true); tiempo = new JLabel(); tiempo.setLocation(0, 30); tiempo.setSize(200, 60); tiempo.setPreferredSize(new Dimension(200, 60)); tiempo.setOpaque(true); tiempo.setBackground(Color.WHITE); tiempo.setText("00:00:00"); iniciar = new JButton(); iniciar.setText("Correr"); iniciar.setLocation(0, 0); iniciar.setSize(100, 30); iniciar.setPreferredSize(new Dimension(100, 30)); iniciar.setVisible(true); iniciar.addActionListener((event) -> { tiempo.setText("00:00:01"); }); add(iniciar); add(tiempo); } }