0

I have a Java GUI that I'm developing and I've run into a snag with regard to the default size of the "thumb" on a JSlider I need for user input for the simple and unavoidable reason that the application has to run on a touch-screen, there is no mouse, and the precision of the touch of a finger is just not good enough to make it easy to "get a grip" on the slider to move it. The touch screen is all there is... it just isn't that precise.

NO PROBLEM, I thought! I'll just customize it and make the "thumb" bigger! In doing my research I found this previously asked question, and it has what looks like helpful data, but I couldn't figure out how to get that to work. In the answers to that question it points to this page where it purports to show how it's done, but ... it then doesn't show it?!

I guess they presume you know what to do with the likes of:

Slider.thumbHeight  Integer
Slider.thumbWidth   Integer

But, I don't! Anybody got any code snippet of an example?

I played around, incompetently, with stuff like this that I really don't quite understand:

UIDefaults defaults = UIManager.getDefaults();
defaults.put("Slider.thumbHeight", 45);
defaults.put("Slider.thumbWidth", 15);

...With no success, though it does compile just fine. I tried creating the slider after this. Nope. I tried mySlider.updateUI(); Nope. And, of course, this won't compile at all: mySlider.thumbHeight(40); ...I just don't quite grock how one is supposed to customize these things.

Thanks in advance.

Richard T
  • 4,570
  • 5
  • 37
  • 49

1 Answers1

0

Old post I know, but still may be relevant for others anyway.

"Slider.thumbHeight Integer" just tells you that the variable is of type integer and thus expects a whole number as an argument when you set it.

You have to change the UIdefaults (as in your example) before you create the JSlider.

This said it seems to be operating system dependent whether it works or not. It worked well on my Windows10 PC but not on Raspbian Linux where I really needed it :-(

omh
  • 1