I was trying to add JSlider
to JPanel
but it does not appear.
Could you tell me where I'm wrong?
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
public class Principal extends JFrame{
public static JPanel pn = new JPanel();
public static final int VelMin = 0;
public static final int VelMax = 20;
public static final int VelInit = 10;
public static JSlider jsVelocidade= new JSlider(JSlider.HORIZONTAL, VelMin, VelMax, VelInit);
public static void main(String[] args) {
new Principal();
}
public Principal(){
super("Semáforo");
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
pn.setPreferredSize(new Dimension(800,500));
pn.setLayout(null);
jsVelocidade.setMajorTickSpacing(10);
jsVelocidade.setMinorTickSpacing(1);
jsVelocidade.setPaintTicks(true);
jsVelocidade.setPaintLabels(true);
pn.add(jsVelocidade);
add(pn);
pack();
setVisible(true);
setLocationRelativeTo(null);
}
}