• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JSlider

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
At the beginning I paste simple image.


My question is there a chance to change these three elements ?

I want to add main own paintTrack and the element marked number one in this image.
 
Sheriff
Posts: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those are part of the UI. You can create a new SliderUI class and install that for the JSlider. It's not going to be easy though.
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe somebody has some example ?
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think about to create panel which background imitating paintTrack and adding to it some custom for example circle Graphics. Next i can add to my Graphics the mouseListener and write code to move this graphics this will imitate JSlider behavior.

but i don't know how this solutions will affect the application performance.

What do you think about this ?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, don't reinvent JSlider. Extend the UI delegate of your chosen L&F and override paintThumb and paintTrack. Start with the JDK code, eliminate or substitute any private variables and/or method calls that aren't available in a subclass and then tweak it from there.

For example, for the default Metal L&F tou would extend MetalSliderUI. In case you didn't know, you can find the JDK source in the file src.zip in your JDK directory.

Why do you need to do this anyways?
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to create Slider with my own graphics. I write this but the slider doesn't displayed. I really don't know how i should to started with this UI.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting properties of a Graphics reference doesn't paint anything. Did you go through the code in the same methods of MetlaSliderUI?

Time for a couple of tutorials:
http://download.oracle.com/javase/tutorial/uiswing/painting/index.html
http://download.oracle.com/javase/tutorial/2d/index.html

For the thumb Icon, you can create an Icon and set it usingSee the Icon interface for the three methods you have to implement.

You didn't answer this:

Why do you need to do this anyways?

 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl look at this photo, i want to create something like this so i need t change those three elements but question is how ?

1. Standard JSlider
2. look who i wants to achieve


 
Rancher
Posts: 3063
23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you need to add code like the following to your MSlider class:



Then you can add System.out.println(...) statements to your paintThumb() and paintTracks() methods to make sure they are being invoked.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good luck developing this further for flexibility of usage. Oh, and you owe me a beer.
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much guys )
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl the code that you pasted was created with using some program or you wrote it yourself ?
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know of any program that can generate UI customization code. Here are the steps I followed, so that next time round you can do this yourself.

1. Examined the Slider properties that can be set via the UIManager using Rob Camick's UIManager Defaults.

2. Attempt to customize those properties: succeeded for the 3 properties as in the 3 UIManager.put(...) statements in the code. Failed for Slider.trackWidth (default value: 7).

3. Developed an Icon using the Graphics2D API (Note: except in the earliest versions of Java, all Graphics objects are instances of Graphics2D) and a suitable Paint.

4. Examined the code of MetalSliderUI and BasicSliderUI. Found that trackWidth is read but never used. (!)

5. Examined the paintTrack(...) method in both those classes. Decided the one in BasicSliderUI was adequate for the desired customizing.

6. Utilized the to Graphics2D API to draw the track using a suitable Stroke.

7. Increased the preferredSize to match the size of the posted image.

The colors were taken from the image you posted, using the hex values obtained via the color picker in a graphics editing program. Since your image was a JPEG, some compression artifacts made it impossible to guess the true original color. A PNG might have been better: lossless compression.

You still haven't told me why exactly you required this customization.
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you again Darryl. The reason why i need this customization is simple. I create some program and i want to add my own graphics. I couldn't do it with standard JSlider method so render my own JSlider is the only way to do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!