Adding Interior Bounds to a Slider

I am attempting to create a version of JSlider which has interior bounds that its value must respect. Included in the default Bounded Range model, employed by JSlider, is a value called extent, whose function is similar to the end product I am working towards. The Default Bound Range Model has the following constraints for its values:
min <= value <= value + extent <= max
where min is the minimum value, max is the maximum value, value is its current value and extent is a sort of buffer that limits how close value can get to max. When this model is employed by JSlider, it usually has extent set to zero, but if extent takes on a non zero value, then the slider will prevent the thumb from being dragged all the way max value, with extent being the closest to max it can get. I would like to have this effect on both the left and right sides of the slider, effectively decreasing the sliders range by a total of 2*extent.
In order to do this, I have extended the default bounded range model so that it now obeys the following constraint:
min <= value - extent <= value <= value + extent <= max
where extent can only take on values between zero and (max - min)/2. If value is found to be too large or small to obey the constraints involving extent, then value is adjusted so that extent is maintained and value is found within the inner bounds.
So as it is now, the Model seems to be working, enforcing an inner boundary defined by extent, but the visual representation (the slider) does not reflect this. Below is a simple class that displays the problem. The window includes a label to the right of the slider which displays the slider's current value. As you can see, you cannot pull the thumb past 80 (because extent = 20), but you can pull the thumb all the way to zero, though value will not go below 20. If you resize the window, forcing it to repaint the component, then the thumb moves up to 20, where it should be. Also, only drag events cause this problem, simply clicking or using the arrow keys will not take the thumb below 20. How do I fix this? I have tried extending JSlider and rewriting the setValue() method so that it calls repaint() or revalidate(), but that does not work. Please help!!! Thank you so much! (sorry for the long explanation)
Here is the code:
/*BoundedSliderTest.java */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.DefaultBoundedRangeModel;
public class BoundedSliderTest extends JPanel
implements ChangeListener {
private JSlider slider;
private JLabel label;
private int extent;
private int min;
private int max;
private int initValue;
public BoundedSliderTest() {
     min = 0;
     max = 100;
     initValue = 50;
     extent = 20;
public void init() {
     setLayout(new BorderLayout(5,5));
     DoubleBoundedRangeModel myModel = new DoubleBoundedRangeModel();
     slider = new JSlider();
     slider.setModel(myModel);
     slider.setMinimum(min);
     slider.setMaximum(max);
     slider.setExtent(extent);
     slider.setValue(initValue);
     slider.setMajorTickSpacing(20);
     slider.setMinorTickSpacing(2);
     slider.setPaintLabels(true);
     slider.setPaintTicks(true);
     slider.addChangeListener(this);
     Dimension size = new Dimension(3slider.getMinimumSize().width,
                    slider.getMinimumSize().height);
     slider.setMinimumSize(size);
     slider.setPreferredSize(size);
     slider.setMaximumSize(size);
     label = new JLabel(String.valueOf(slider.getValue()));
     add(slider, BorderLayout.CENTER);
     add(label, BorderLayout.EAST);
public void stateChanged(ChangeEvent e) {
     JSlider source = (JSlider)e.getSource();
     int value = (int)source.getValue();
     label.setText(String.valueOf(value));
public static void main(String [] args) {
     JFrame frame = new JFrame("Bounded Slider Test ...");
     frame.getContentPane().setLayout(new BorderLayout());
     MyWindowListener l = new MyWindowListener();
     frame.addWindowListener(l);
     BoundedSliderTest test = new BoundedSliderTest();
     test.init();
     test.setOpaque(true);
     frame.getContentPane().add(test,BorderLayout.CENTER);
     frame.pack();
     frame.setVisible(true);
     frame.show();
class MyWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
     System.exit(0);
class DoubleBoundedRangeModel extends DefaultBoundedRangeModel{
public DoubleBoundedRangeModel() {
public int getValueRules(int tryValue) {
     int extent = super.getExtent();
     int min = super.getMinimum();
     int max = super.getMaximum();
     if((tryValue-extent) < min){
     tryValue = min + extent;
     if((tryValue+extent) > max) {
     tryValue = max - extent;
     return tryValue;
public void setValue(int newValue) {
     //System.out.println("Try setting value of " + newValue);
     int value = super.getValue();
     int extent = super.getExtent();
     int min = super.getMinimum();
     int max = super.getMaximum();
     //Now must ensure compliance with inner bounds;
     if((newValue-extent) < min){
     newValue = min + extent;
     if((newValue+extent) > max) {
     newValue = max - extent;
     if( newValue != value)
     super.setValue(newValue);
public void setExtent(int newExtent) {
     int value = super.getValue();
     int extent = super.getExtent();
     int min = super.getMinimum();
     int max = super.getMaximum();
     if (newExtent < 0)
     newExtent = 0;
     else if (newExtent > (int)Math.floor((max - min)/2.))
     newExtent = (int)Math.floor((max - min)/2.);
     if( newExtent != extent)
     super.setExtent(newExtent);
public void setRangeProperties(int newValue,
                    int newExtent,
                    int newMin,
int newMax,
boolean newAdjusting) {
     //System.out.println("setRangeProps");
     int value = super.getValue();
     int extent = super.getExtent();
     int min = super.getMinimum();
     int max = super.getMaximum();
     boolean isAdjusting = super.getValueIsAdjusting();
if (newMax < newMin) {
if(max >= newMin)
          newMax = max;
     else if(min <= newMax)
          newMin = min;
     else {
          newMin = min;
          newMax = max;
     if (newExtent < 0)
     newExtent = 0;
     else if (newExtent > (int)Math.floor((newMax - newMin)/2.))
     newExtent = (int)Math.floor((newMax - newMin)/2.);
     if (!bounded(newMin,newMax,newValue)) {
     if (newMin == newMax)
          newValue = newMin;
     else if (bounded(newMin,newMax,value))
          newValue = value;
     else
          newValue = (int)Math.round((newMax+newMin)/2.);
     //Now must ensure compliance with inner bounds;
     if((newValue-newExtent) < newMin){
     newValue = newMin + newExtent;
     if((newValue+newExtent) > newMax) {
     newValue = newMax - newExtent;
boolean changeOccurred = false;
if (newValue != value) {
value = newValue;
changeOccurred = true;
if (newMax != max) {
max = newMax;
changeOccurred = true;
if (newMin != min) {
min = newMin;
changeOccurred = true;
if (newExtent != extent) {
     extent = newExtent;
changeOccurred = true;
if (newAdjusting != isAdjusting) {
isAdjusting = newAdjusting;
changeOccurred = true;
if (changeOccurred)
super.setRangeProperties(newValue, newExtent, newMin, newMax,
                    newAdjusting);
private static boolean bounded(int lowBound, int highBound,
                    int num) {
     boolean bounded = false;
     if(num >= lowBound && num <= highBound) bounded = true;
     return bounded;

perrymanp-
I tried employing your suggestion by including the following code in my stateChanged listener for the slider, but it had no effect... maybe I am missing something? Thanks.
     BoundedRangeModel brm = source.getModel();
     source.setModel(new DoubleBoundedRangeModel(value,brm.getExtent(),
                              brm.getMinimum(),
                              brm.getMaximum()));
-kheldar83
PS any more suggestions or clarifications are greatly appreciated!

Similar Messages

  • TS2446 A email account that was used is now not in use and songs that were purchased and added are bound to this old account from the same computer how do I the purchaser of these songs reclaim the authorization to play and use in my new account

    A email account that was used is now not in use and songs that were purchased and added are bound to this old account from the same computer how do I the purchaser of these songs reclaim the authorization to play and use in my new account. even though account name may have been changed.

    Just authorize the computer and retreive them.
    Go here -> https://iforgot.apple.com/cgi-bin/WebObjects/DSiForgot.woa/wa/iforgot .
    FYI: you should have simply updated the AppleID with new info and continued to use it instead of creating a new one.

  • Why apple is not adding tweaks like activator,volume slider in multitasking bar and a blacklist app

    Why apple is not adding tweaks like activator,volume slider in multitasking bar and a blacklist app?

    But quantity is not everything.
    Funny, because Windows proponents and users touted the quantity of apps available with that swiss cheese for security OS being "everything" or a big plus, but now say it isn't everything with iOS. Can't have it both ways.
    At present there are about SIX blacklist apps in the OFFICIAL Apple Store which I can buy for MONEY but have NO USE AT ALL because of the APIs restrictions.
    3rd party apps don't have access to private iPhone APIs for security reasons. Andrioid is following the same path as Windows. Their so called "open" OS is a swiss cheese for security mobile OS.
    If this isn't acceptable to you or having an option to block unwanted calls provided by the iPhone's OS is a very important want or need, stick with an Android or Symbian device that includes the option. 

  • Doco/functionality mismatch: Adding a Bounded Task Flow to a Page

    Hi JDev team
    With JDev 11g TP4 and the latest published ADF Guide in hand, under section 14.3 "Adding a Bounded Task Flow to a Page", subsection "To add a bounded task flow containing pages to a JSF page:" it notes that when you drag n drop a bounded task flow from the App Navigator into a JSF page you get the choice of creating a button or link. I don't get this option, instead I can create a region or a dynamic region in the drag n drop submenu.
    Cheers,
    CM.

    Chris,
    note that it says "containing pages", not "containing page fragments". If your taskflow contains page fragments "jsff" then the choice is a region, if it is pages (jspx) then the choice is button or link to launch the taskflow.
    Let me know if this still doesn't work for you
    Frank

  • Adding variables to match question slides

    Hi All,
    I am using Captivate 7 and need your help/idea/expertise on this. I am trying the following:
    Adding a drag and drop slide wherein I should be able to drop the source to any target.
    If the drop happens on the correct option (this is the challenge, how can I define the correct answer!), a message should flash saying "You are right"
    If even a single drop goes wrong, then I the right answers should flash, (this I can create a new slide though)
    But to set such conditions what should I exactly do? Please help.
    Thanks,
    Roja

    The title of your question is bit confusing. Why should you have to add variables to match question slides?
    The content of your question is totally different: each D&D slide can act as a question slide. It doesn't really have all the features of a question slide but most of them: Reporting, Score (only black/white, not partial score/penalty), Attempts, Actions On Success/Failure. When it is configured as a question its score will be reset when the user 'Retakes' a quiz with multiple attempts on quiz level etc. Progress quiz indicator will not be included however. And defining the correct answers is a breeze with the wizard or with the button Correct Answers.
    The best part about D&D are IMO the 'Object actions': you can specify an advanced action for each drag&drop act and that is what you need. Do not use a simple action, because it will release the play head. That action can show a feedback text/object that was previously hidden, it can apply an effect to an object like flashing, etc. This blog post was written for CP8, but can help maybe:
    Drag&Drop tips - Captivate blog

  • Adding automatic stops afer each slide in a recorded project

    I have a project recorded as demonstration, but I want to
    make it stop after each slide and advance only on user action. I
    don't want to be adding any buttons or anything - I am content with
    the playback control provided by captivate. I don't see any reason
    creating my own secondary navigation,
    I just want user to use Forward and Backward buttons from
    Captivate Playback control to navigate between the slides - but the
    movie keeps playing constantly.
    Please, is there an easy way how to make all slides in a
    project stop at end? Thank you!

    Hi Skippi.sk and welcome to our community
    The only way to accomplish this is to insert either a click
    box or a button on each slide. Probably the easiest way is using a
    click box. object. Insert it on the first slide, size and position
    as needed, then copy it. Then select slides two through the end and
    paste the object.
    Hopefully this helps... Rick

  • Adding photo collage image to slide show in photoshop elts 9

    I created a photo collage page using photoshop elements 9 and saved it as a jpg file. It looked clear and sharp on screen.   When creating slide show, I added this page but when I play the slide show full screen, the image for this page is blurer than normal.  Other regular photos I added in the slide show are ok.  Why does this happen and is there a way to overcome it?

    Maybe it's me, but... scoobie... i don't think your reply has anything to do with her question lol. I believe she's saying she is having trouble figuring out how to do something, not that the program is crashing.
    Anyway, I'm starting a similar slideshow project. I think it's easiest to simply edit the photos in iPhoto. Photoshop is on a different level from iPhoto and obviously has capabilities iPhoto lacks, but I think it should be fine for just editing digital photos.
    One of the things you said was "how do you format... resolution"
    I don't think iPhoto can change the resolution of a photo like photoshop can, but since you want to make the FINEST quality slide show I assume you'd want to scale the resolution up... and although photoshop can do that, I don't think you'll see a significant increase in quality. It won't look anything like if you had actually taken the photo at a higher resolution.
    As far as importing pictures into iMovie goes, that should be pretty easy. If you click on the "media" button in iMovie, and then click on the "Photos" tab on the upper right of the window, it will display your iPhoto library the same way it would display it in iPhoto (organized by albums). You can then drag whatever photos you want to include to the "timeline" at the bottom of the screen.
    I'm not sure what to tell you about pixel ratio and RGB vs. CMYK....
    The last step, exporting to iDVD is just as simple as adding pictures... just click on the "Share" menu at the top of the screen and select "iDVD". What you do from there depends on what kind of final product you want... and I haven't actually used iDVD so I would just be guessing on that part lol.
    Also, I suggest going here: http://www.apple.com/ilife/tutorials/imovie/index.html and looking at the tutorial. I viewed most of the movies there and they were helpful.

  • Adding a logo to every slide in my presentation in Keynote '09

    I can't seem to figure out how to add a logo to each slide automatically something like a slide number is added automatically when the proper selections are set. The item I would like on each slide is a four letter logo on the lower left corner of each slide.

    Are you putting your logo directly on to the slide, or are you putting it on the MASTER SLIDES? On the left side of the display (below New, Play and perhaps Skip) you should have 2 stacked, vertical columns titled Master Slides and Slides. If you only see Slides, then grab the handle to the right of the title and drag it down to find your Master Slides. Open each of the masters and copy and paste your logo on to them. Now it will appear on every slide.

  • Adding swf animation to Captivate Slide

    Hello Forum Members,
    I have a problem. I just used Flash (CS3 Pro) to make a small
    animation that moves a few objects
    across the stage, and has glow filters, etc. I have also
    added eventlisteners for mouse over and mouse out on this swf. The
    swf plays fine in standalone mode (in Flash Player, etc). I have an
    object that gets created via action script in this swf as well as
    objects already on the stage (design time).
    I then insert this swf file into a Captivate (3.0) slide -
    the animations do not play correctly, my object that gets created
    in the swf timeline never appears, and the rollover/out actions do
    not play. Am I not understanding the capability of Captivate to
    "play" Flash animations? I was hoping to use this flash element in
    my Captivate project.
    Thanks for a helpful forum,
    eholz1

    Thanks for your reply!  Here's a better explanation of my end goal.
    I want to create a software simulation.  I want my question to look and
    function interactively in a limited way just like the piece of software.  I
    will then ask them to do a task using this software and mark them correct if
    they finish it correctly.
    For example, if I was using MS Word I want a master slide that includes the
    menu drop downs and hover effects that would match the actual program.  I
    could use those over and over and each question just add the content unique
    for the question.
    Does that make sense?  Can Captivate do that?

  • When adding music to an iphoto slide show, is it possible to sample pieces of songs?

    Does anyone simply sample bits of music for their slide shows? I have only been able to apply entire songs.

    You can't. Iphoto plays the music track. It's it's 3 minutes long then it plays for 3 minutes.
    So if you want to play segements you'll need to copy the track, duplicate it and edit it to the requied length
    Or
    Use an app that supports multiple audio tracks.
    Alternatives to iPhoto's slideshow include:
    iMovie, on every Mac sold.
    Others, in order of price: PhotoPresenter  $29
    PhotoToMovie  $49.95
    PulpMotion  $129
    FotoMagico $29 (Home version) ($149 Pro version, which includes PhotoPresenter)
    Final Cut Pro X $299
    It's difficult to compare these apps. They have differences in capability - some are driven off templates. some aren't. Some have a wider variety of transitions. Others will have excellent audio controls. It's worth checking them out to see what meets your needs. However, there is no doubt that Final Cut Pro X is the most capable app of them all. You get what you pay for.

  • Added help button to quiz slide

    I am trying to add a help button to a quiz slide. I would
    like ti to pull up a slidelet or go to another slide with a image.
    All my buttons and click boxes are disabled on question slides.
    Any help would be appreciated.
    -Mark

    Hi Mark
    I believe you could accomplish this as follows:
    Create a blank Captivate project that is the same size as
    your existing project. Create the slidelet as part of this project.
    Define the rollover area and whatever else you need. Be sure to
    pause the project so the slidelet will work without the playhead
    just moving on.
    Publish this as a .SWF. You may DE-Select the HTML check box
    so all you end up with is the .SWF.
    Open the project with the Question slide. Edit the Question
    slide and click Insert > Animation. Browse to and select the
    .SWF you just created. This should allow you to insert a Slidelet
    on a Question slide.
    Cheers... Rick

  • Adding "home" button to every slide

    I have a 50+ slide Captivate document and I'd like to add a
    "home" button on every slide without having to paste it into every
    one. Any way to do this? Is there a master slide or something I can
    add it to and have it appear on all?
    Thanks!

    Hi wfz and welcome to our community!
    Unfortunately you don't have a lot of choice in placement of
    these beasties. So you either use what you have or develop a
    workaround. I'm thinking you will perhaps need to insert a button
    object on each slide that is labeled "Home" and points to the
    appropriate slide.
    You should also consider submitting a WishForm asking the
    developers to provide us more flexibility in placing the existing
    menu. You may do this by
    clicking
    here and completing the forum you should find there.
    Cheers... Rick

  • Adding sequential numbers to a slide show using Lightroom 4.4?

    How do you add sequential numbers to a slide show using Lightroom 4.4? I want images to show sequentially with each having a specific number such as 1 of 25, 2 of 25, 3 of 25 and so on. Please advise.

    Sorry, that computer is not connected to the internet right now- husband is using wifi to watch World Cup. Here's a picture from my phone. If it's too hard to read I can take a screen shot in an hour or so.
    Thank you both in advance for your help.

  • Losing work and freezing up in Captivate 4 when adding any objects or recording slide

    I've been using C4 for two months without any big issues until now. I can't record any new screens to my current file without the whole program crashing. In addition, I can't paste in the objects that make the project interactive without crashing.
    I've tried deleting all my temp files (the error window referenced temp files)
    disconnecting from the network
    rebooting a dozen times
    closing and reopening the program a dozen times
    moving my files off my desktop (the path to the file is short and on my local drive--as the forums suggest) and onto the network, then back again
    Nothing has worked.
    The project is only 50 slides, so it is not excessively large.
    I just tried opening an older file from  a previous project and copying and pasting objects within that file. It worked fine.
    This tells me the issue is likely with the current project and the way we built it from a previous project file ( we used the previous project as a template for the new one). It must have something in it that is slowing it down and creating errors.
    I don't know what to do except to rebuild the whole lesson in a new file. This has put me 3 days behind on a milestone that does not have any wiggle room.
    I got three screens edited in 4 hours yesterday.
    Can anyone tell me what the fix would be for this? Is the best practice to not use old projects as templates? Is the only fix to copy and paste slides into a new project file?
    Thanks in advance for any advice you can give.

    One more thing I forgot to mention, the day before this issue arose, I turned off the function to make backup project file. I did turn it back on when I started losing work with all the crashes.

  • POI HSLF trouble adding a table to a slide

    got the error when i was trying to execute the code below (slide.addShape(table); ), this is pretty much the example code that i got from
    http://www.java2s.com/Open-Source/Java-Document/Collaboration/poi-3.0.2-beta2/org/apache/poi/hslf/examples/TableDemo.java.htm
    i tried poi-scratchpad-3.5-beta3 and poi-scratchpad-3.1-final.jar, same error
    can anyone please help? thank you
    java.lang.ClassCastException: org.apache.poi.ddf.EscherSpRecord cannot be cast to org.apache.poi.ddf.EscherOptRecord
         at org.apache.poi.hslf.model.Table.afterInsert(Table.java:119)
         at org.apache.poi.hslf.model.Sheet.addShape(Sheet.java:250)
    SlideShow ppt = new SlideShow();
         Slide slide = ppt.createSlide();
         Table table = new Table(1, 1);
         TableCell cell = table.getCell(0, 0);
         cell.setText("TEST");
         slide.addShape(table); // line 119

    Ok  I have the table  on the page  I created a css with a background image called .search  How to I link that to the table so It shows the image
    I am only used to doing certain css items   Never didi this before
    THXS STeve

Maybe you are looking for

  • I use Firefox 4. Stop pestering me to upgrade to Firefox 5.

    I was happy with Firefox 4. The toolbar across the top was very important. When I downloaded Firefox 5 I lost years of valued information. I was very angry. I am an average user not a computer geek. Somehow by fooling around I managed to download Fir

  • Customer account relationship to Active

    Hi, we are facing issue when the calling this api for the update the customer account relationship to Active. We passed the CUST_ACCOUNT_ID, RELATED_CUST_ACCOUNT_ID and status = 'A' . HZ_CUST_ACCOUNT_V2PUB.update_cust_acct_relate( p_init_msg_list =>

  • CS6::canceling a keystroke

    Hi I have an edit box that may accept only alpha characters. I added my own iplementantion of IID_IEVENTHANDLER on my kTextEditBoxWidgetBoss. I get the event but, I do not know how to cancel, I try this code, it seems to work in windows, but it fails

  • OCR is get corrupted

    Hi experts my OCR get corrupted and can any one guide me how to replace it. below is the details of my envoirnment O/S RHEL 4.5 ORacle 10g RAC(10.2.0.1) OCFS2.1 as cluster file system Raw devices for OCR and voting disk with extented option please gu

  • Stopped importing from Kodak

    Hey, I have been using iPhoto 9 with my Kodak Z1275 for the last year without problem. However I am trying to get some recent photos from my camera and iPhoto cannot get them. When I connect my camera iPhoto loads as usual and after a time my camera