Question

I have a question about getting a JSlider to point the left instead of right.. BUT, I need it to do so only for one JSlider. This question is very similar but the answer to it only helped if you wanted all JSliders to point the wrong way. Here is a photoshopped image of what i want.

JSliders

Was it helpful?

Solution

I found out how to do it. All i needed to do was make a new class.

package Main;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

import javax.swing.JSlider;

public class ReversedJSlider extends JSlider{
private static final long serialVersionUID = 1L;

    public ReversedJSlider() {
        super();
    }

    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        AffineTransform tx = new AffineTransform();
        tx.translate(50, 0);
        tx.scale(-1, 1);
        tx.translate(-50, 0);
        g2d.setTransform(tx);
        super.paintComponent(g2d);
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top