Ginchen
Ginchen

Reputation: 790

JavaFX 8 Slider: Min value and Major Tick Unit

I have this JavaFX Slider:

JavaFX slider

As you can see, the min value is 1 and the major tick unit is 5.

But what I'd like to achieve is this:

desired look 1

or at least this:

desired look 2

So basically, I want to move the whole scale to the left by 1 tick. But how?

(I also saw this post, but isn't there a quicker and easier way? Or do I really have to define my own Slider for this little task?)


Edit

Okay, I tried to make my own slider then. But I'm really lost.

This is what I want to do logically; but I don't know how to do it practially:

public class ImprovedTicksSlider extends Slider {

    public void setTickMarks(int majorTickUnit, int minorTickCount) {
        // 1.)
        // set the first major tick mark at
        // getMin() + (majorTickUnit - getMin() % majorTickUnit)

        // 2.)
        // set minor tick count in the very first block to:
        // majorTickUnit - (getMin() % majorTickUnit)

        // 3.)
        // set all other major tick marks at positions where
        // (x % majorTickUnit == 0)

        // 4.)
        // set all other blocks of minor ticks to (minorTickCount)
        // like it would usually be the case in a standard Slider

        // ...but how?!
    }
}

Upvotes: 0

Views: 1755

Answers (1)

Kevin T.
Kevin T.

Reputation: 21

I think you pretty much got it. You'll have to use a custom Slider since this basic slider only supports regular tick intervals.

The custom slider isn't really that big and you can import it in FXML so it's not a big problem.

Upvotes: 0

Related Questions