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 8298641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:51:21+00:00 2026-06-08T15:51:21+00:00

I have a JSlider component on my frame which is being constantly updated by

  • 0

I have a JSlider component on my frame which is being constantly updated by an external component (a media player which sets a new value from time to time). I want the slider to handle the stateChanged event only when I manipulate the slider and not my external component.

Is there any way to achieve this?

  • 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. Editorial Team
    Editorial Team
    2026-06-08T15:51:23+00:00Added an answer on June 8, 2026 at 3:51 pm

    I’d implement my own BoundedRangeModel, this way you can add additional flags that indicates whether it should accept updates or not

    UPDATE with EXAMPLE

    The basic idea would be to implement your own model, that way you can control when the value is actually changed

    public class MyBoundedRangeModel extends DefaultBoundedRangeModel {
    
        private boolean updatesAllowed;
    
        public void setUpdatesAllowed(boolean updatesAllowed) {
            this.updatesAllowed = updatesAllowed;
        }
    
        public boolean isUpdatesAllowed() {
            return updatesAllowed;
        }
    
        @Override
        public void setMinimum(int n) {
            setUpdatesAllowed(true);
            super.setMinimum(n);
            setUpdatesAllowed(false);
        }
    
        @Override
        public void setMaximum(int n) {
            setUpdatesAllowed(true);
            super.setMaximum(n);
            setUpdatesAllowed(false);
        }
    
        @Override
        public void setExtent(int n) {
            setUpdatesAllowed(true);
            super.setExtent(n);
            setUpdatesAllowed(false);
        }
    
        @Override
        public void setValue(int n) {
            super.setValue(n);
        }
    
        @Override
        public void setValueIsAdjusting(boolean b) {
            setUpdatesAllowed(true);
            super.setValueIsAdjusting(b);
            setUpdatesAllowed(false);
        }
    
        @Override
        public void setRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting) {        
            if (isUpdatesAllowed()) {
                super.setRangeProperties(newValue, newExtent, newMin, newMax, adjusting);
            }
        }
    
    }
    

    This would allow you to control the change of the “value” property. The problem you have here is that ALL the set methods go through the setRangeProperties method, so you need to decide what should be allowed to effect it. In my example, the only method that does not control it is the setValue method.

    In your code you would need to call it something like…

    MyBoundedRangeModel boundedRangeModel = new MyBoundedRangeModel();
    slider.setModel(boundedRangeModel);
    
    ...
    
    boundedRangeModel.setUpdatesAllowed(true);
    slider.setValue(value);
    boundedRangeModel.setUpdatesAllowed(false);
    

    Your only other choice is to extend the JSlider itself and override the setValue method directly in a similar way

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a progress bar which inherits from JSlider to provide highlighting functionality. Highlights
I have a JSlider that sets the speed of my metronome, from 40 -
Say I have a standard Swing component like JSlider, but I want to slightly
I have a JSlider which shows bet sizes (for a poker game) I am
I have this custom JSlider, which will be used in many other forms/windows. But
Let's say I have a horizoltal JSlider from 0 to 100. What i want
Have converted devise new session from erb to Haml but doens't work, this is
I have built a small app that has a JSlider which controls the speed
Have a bunch of classes which I need to do serialize and deserialize from/to
I have a JSlider with a min of 0 and a max of 10,000.

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.