I’m trying to add a slider to my frame using JSwing components, but for some reason it’s not working. I tried looking up possible solutions but they either don’t apply or haven’t worked for me such as setting the size or visibility and what not. Basically, why doesn’t my slider show up?
I’ve got a carIcon that shows up just fine, but the slider won’t. Here’s my code.
public static void main(String[] args)
{
JFrame frame = new JFrame("Slider Tester");
MoveableShape shape = new CarShape(125, 100, CAR_WIDTH);
slider bar = new slider();
ShapeIcon icon = new ShapeIcon(shape,
ICON_WIDTH, ICON_HEIGHT);
JLabel label = new JLabel(icon);
frame.setLayout(new FlowLayout());
frame.add(label);
frame.add(bar);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(100,100);
frame.pack();
frame.setVisible(true);
}
and my slider
public class slider extends JPanel implements ChangeListener
{
private JSlider carSlider;
public slider()
{
carSlider = new JSlider();
carSlider.addChangeListener(this);
}
@Override
public void stateChanged(ChangeEvent ce)
{
}
}
The
slideris not added to the panel.Add this line to
sliderconstructor: