我目前正在为学校制作一个程序,我必须在调整 JSliders 时锁定比例。
我无法弄清楚如何在更改第一个 slider 时使一个 slider 更改为相同的值。 我想以 1:1 的比例更改 slider ,因此如果我将宽度滑动到 5,长度也会增加 5,但我不知道如何找到一个常数差异来计算更改值时的情况。
最佳答案
在您的代码中,您根据 length.getValue
设置长度值,但您希望长度随着宽度的变化而设置,反之亦然。所以我建议你设置长度,如 length.setValue(width.getValue());
if(lkRatio.isSelected() !=true){
tempw = width.getValue();
templ = length.getValue();
diff = width.getValue() - length.getValue();
}
if(lkRatio.isSelected()){
if(source == width){
length.setValue(width.getValue() - diff);
}
if(source == length){
width.setValue(length.getValue() + diff);
}
}
关于java - 将 2 个 slider 移动到一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50500151/