Re: Setting extent in JSlider model
On 2/3/2012 12:35 PM, Fred wrote:
How can I set how much a slider will change when the user hits the
PageUp of PageDown key, and when the user clicks in the slider's
trough?
The javadoc for JSlider's model (BoundedRangeModel) setExtent() method
states:
When used with a slider, the extent determines how much the value
can "jump", for
example when the user presses PgUp or PgDn.
However, setExtent() seems to have no effect. When I use the PgUp or
PgDn key, the value always changes 10% of the range regardless of the
value I request for extent.
As for clicking in the trough, metal L&F always seems to increment (or
decrement) the value by one, and for Nimbus it is the same as PgUp/
PgDn.
--
FredK
It can be very annoying when the L&F prevents a change to a value that
has a setter method. You might look to see if you can find a UI
property that could change that. The problem is that I've found even if
there is a UI property the methods in the L&F may not honor them. I
extended a menu item class to be able to do that but it may or may not
work in the future. I just figured it was a quick fix for the moment
and if it didn't work in the future I could take it out.
This program will list all the UIDefaults:
import java.util.Enumeration;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
public class ListUIProperties {
public static void main(String args[]) throws Exception {
UIManager.LookAndFeelInfo looks[] =
UIManager.getInstalledLookAndFeels();
for (UIManager.LookAndFeelInfo info : looks) {
UIManager.setLookAndFeel(info.getClassName());
UIDefaults defaults = UIManager.getDefaults();
Enumeration newKeys = defaults.keys();
while (newKeys.hasMoreElements()) {
Object obj = newKeys.nextElement();
System.out.printf("%50s : %s\n", obj, UIManager.get(obj));
}
}
}
}
--
Knute Johnson