1
I was trying to add a JSlider
in a JPanel
but he doesn’t show up.
Could you tell me where I’m going 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);
}
}
But there is a way I can use Jslider without taking Pn.setLayout(null)?
– Gustavo Cruz
@Not Gustavocruz. If you set a layout to null, you are removing it from the component.
– user28595