Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 136293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:55:31+00:00 2026-05-11T06:55:31+00:00

Whenever I click a JSlider it gets positioned one majorTick in the direction of

  • 0

Whenever I click a JSlider it gets positioned one majorTick in the direction of the click instead of jumping to the spot I actually click. (If slider is at point 47 and I click 5 it’ll jump to 37 instead of 5). Is there any way to change this while using JSliders, or do I have to use another datastructure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:55:32+00:00Added an answer on May 11, 2026 at 6:55 am

    As bizarre as this might seem, it’s actually the Look and Feel which controls this behaviour. Take a look at BasicSliderUI, the method that you need to override is scrollDueToClickInTrack(int).

    In order to set the value of the JSlider to the nearest value to where the user clicked on the track, you’d need to do some fancy pants translation between the mouse coordinates from getMousePosition() to a valid track value, taking into account the position of the Component, it’s orientation, size and distance between ticks etc. Luckily, BasicSliderUI gives us two handy functions to do this: valueForXPosition(int xPos) and valueForYPosition(int yPos):

    JSlider slider = new JSlider(JSlider.HORIZONTAL); slider.setUI(new MetalSliderUI() {     protected void scrollDueToClickInTrack(int direction) {         // this is the default behaviour, let's comment that out         //scrollByBlock(direction);          int value = slider.getValue();           if (slider.getOrientation() == JSlider.HORIZONTAL) {             value = this.valueForXPosition(slider.getMousePosition().x);         } else if (slider.getOrientation() == JSlider.VERTICAL) {             value = this.valueForYPosition(slider.getMousePosition().y);         }         slider.setValue(value);     } }); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to get the color of one button to change whenever i click
i want to change the incremental for hour and minute, by whenever click on
Whenever I click the ImageView which has a OnClickListener , I get the URL
So whenever I click the button on the startup page, it gives me a
I am getting the following error whenever I click on a postbacking control HttpException
I have table with following structure Whenever user click on checkbook and click on
I created a uiview(with two buttons) covers all the screen whenever i click on
I am customizing the ribbon toolbar and adding a button to it.Whenever I click
I have create a widget in android , whenever i click on Widget TextView
I recently updated my Eclipse (now running 20100218-1602), and I've found whenever I click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.