0
私はJSlider
setValue(int)
を使用して、ユーザがドラッグを終了したときにノブの位置を最も近いティックに自動的に移動しようとしています。位置は、ユーザーがクリックすると正しく設定されますが、ノブをドラッグしたときは正しく設定されません。チックスはどのように修正するのですか?ノブをドラッグした後のスライダの値を変更する
/**
* Called when the slider is moved.
*
* @access public
* @param ChangeEvent
* @return void
*/
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
if (! source.getValueIsAdjusting()) {
//let's only allow users to increment by TIMER_SPACING
int fps = (int) source.getValue();
int temp = fps % TIMER_SPACING;
if (temp > TIMER_SPACING/2) {
fps += TIMER_SPACING - temp;
} else {
fps -= temp;
}
source.setValue(fps);
if (fps == 0) {
timer.stop();
} else {
if (! timer.isRunning()) {
timer.start();
}
timer.setDelay(1000/fps);
}
}
}
あなたはイコライザーをコーディングします? – mKorbel
いいえ、しかし同様の機能。 – Wex
[tick to snap](http://docs.oracle.com/javase/7/docs/api/javax/swing/JSlider.html#setSnapToTicks%28boolean%29)はなぜですか? –