EzDevInfo.com

jslider

jQuery Slider plugin (THIS PROJECT IS NOT MAINTAINED ANYMORE, READ BELOW FOR MORE INFO) jQuery Slider plugin

JSlider for doubles

I am making a GUI (using swing) for a poker framework and need some sort of slider to allow players to select a bet size. However the Swing JSlider only works with int values whereas i need something that can support doubles for 1 decimal point. Are there any libraries I can use, or tricks with the JSlider?

Thanks


Source: (StackOverflow)

JSlider question: Position after leftclick

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?


Source: (StackOverflow)

Advertisements

Painting the slider icon of JSlider

Would like to repaint the the marker or the thumb of the JSlider instead of the standard gray. How can I achieve this?


Source: (StackOverflow)

Java: link JSlider and JTextfield for float value

what is the best and easiest way to link a JSlider and a JTextField so that if one changes, the other gets updated too, but there is no recursive loop?

thanks!


Source: (StackOverflow)

How to get thumb icon of swing jslider?

I need to get the thumb icon which is used to select range in Jslider. How to get only the thumb icon from Jslider?


Source: (StackOverflow)

Set the size of a JSlider thumb

How can the size of the thumb be configured for a JSlider?

With the defaults, and a range for the JSlider of 256, the thumb is only a few pixels wide, which makes it quite difficult to control with a mouse.

I am using the Windows 7 look and feel and the slider looks like this:

Screenshot of slider

Enabling paintTicks with a major and minor tick spacing of 0 gives a better (although not preferred) display:

Screenshot of slider with paintTicks enabled

The desired display is shown in the following image - taken from a native Windows 7 application:

Screenshot of native slider


Source: (StackOverflow)

Using Java Dictionary...use a Hashtable?

I'm a bit surprised no one has asked about this specific case, cause it's kind of a weird inconsistency in the java standard libraries:

I'm using swing JSliders with custom labels; the only library call available to assign labels is: setLabelTable(Dictionary labels)

But Dictionary is an abstract class, and its only known subclass in the standard lib is Hashtable, which the api & various IDE's complain about because it's "obsolete."

The obvious thing to do is just use the Hashtable, but I'm wondering two things:

  1. Is there a better way to approach this?
  2. If Hashtable is the only usable class for this (in my opinion) reasonably important library call, on what basis is it "obsolete"?

Thanks!


Source: (StackOverflow)

Change the JSlider look and feel

I have gone through this website Change look and feel of JSlider but except for Slider.altTrackColor nothing else is working. I want to do something like shown in pic1 any suggestion would be of great help. I'm working on JDK 1.6.

UIDefaults defaults = UIManager.getDefaults();    

       defaults.put("Slider.altTrackColor", Color.red);
       defaults.put("Slider.thumb", Color.red);

I have also tried this:

    WindowUtilities.setNativeLookAndFeel();

 // WindowUtilities.setNimbuzzLookAndFeel();

 // WindowUtilities.setJavaLookAndFeel();

WindowUtilities is class that tells the system to use native look and feel, as in previous releases. Metal (Java) LAF is the default otherwise.

public static void setNativeLookAndFeel() {
try {
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
  System.out.println("Error setting native LAF: " + e);
}

I want slider in the right image to be like left


Source: (StackOverflow)

Is this a bug in JSlider?

I've been having some problems using the JSlider class - specifically with tick labels.

The first time I use setMajorTickSpacing and setMinorTickSpacing everything works as expected. However, subsequent calls to setMajorTickSpacing update the ticks, but not the labels. I've written a simple example to demonstrate this behaviour:

import java.awt.event.*;
import javax.swing.*;

public class SliderTest {
    public static void main(String args[]) {
        JFrame frame = new JFrame();
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                System.exit(0);
            }
        });
        frame.setSize(300, 250);

        JSlider slider = new JSlider(0, 100, 0);
        slider.setMajorTickSpacing(10);
        slider.setMinorTickSpacing(1);
        slider.setPaintLabels(true);
        slider.setPaintTicks(true);

        slider.setMajorTickSpacing(25);
        slider.setMinorTickSpacing(5);

        frame.add(slider);
        frame.pack();
        frame.setVisible(true);
    }
}

Two simple work-arounds seem to fix the problem - either using slider.setLabelTable(null) or slider.setLabelTable(slider.createStandardLabels(25)) before the second call to setMajorTickSpacing. Given this, it would seem that the label table is not being updated correctly.

I'm not sure if this is the intended behaviour or not. My first instinct is that updating the tick spacing should also update the labels, but there are also arguments for separating the two.

So I'd like to know which it is - is this a bug in JSlider or the intended behaviour? If it is the intended behaviour, what would be the standout reasons for making that choice?


Source: (StackOverflow)

JSlider not updating?

I'm quite the beginner regarding the whole drawing stuff in windows and I'm kinda stuck at the moment. At the moment I'm just testing the things out.

import javax.swing.*;
import java.awt.*; 
import javax.swing.event.*;

public class test extends JFrame
{
    JSlider slider1; 

    public test()
    {
        slider1 = new JSlider(JSlider.VERTICAL, 0, 50, 0);
        setLayout(new FlowLayout(FlowLayout.TRAILING));

        add(slider1);
    }

    public void changeValue () 
    {
        slider1.setValue(25);
    }

    public static void main(String args[]) {
        test gui = new test();
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gui.setSize(550,250);
        gui.setVisible(true);
    }
}

So I create a JSlider that I call slider1, I give it its orientation and values. When I call the changeValue method it obviously changes the slider1 value. But there's no change on the GUI. Could someone point me into the correct direction? Does it have something with refreshing the GUI?


Source: (StackOverflow)

Java Swing Range Slider U.I

I needed a slider with two knobs on it (representing a range) and I found this nifty one here. However, they created their own U.I. which extends Java's BasicSliderUI. They override the paint method to draw their own knobs. I would like to use the default knobs based on the current look and feel. I tried calling BasicSliderUI's paintThumb method, but this gives me a generic looking knob which doesn't seem to be tied to the current look and feel. As far as I can tell, JSlider gets its U.I. from MultiSliderUI. How can I create a U.I which changes like JSlider's, but draws two knobs instead of one?

Thanks in advance!


Source: (StackOverflow)

Java: Double-Click a JSlider to Reset

I have a JSlider that sets the speed of my metronome, from 40 - 200, where 120 is the default, in the middle.

When the user clicks the metronome button, the metronome plays at the speed displayed on the JSlider - the user drags the slider to the right, the speed of the metronome increases, and it decreases if they slide it to the left.

How do I add functionality so that if the user double-clicks on the JSlider button, it defaults back to 120 - in the middle?

Here is my code:

public Metronome() {
    tempoChooser = new JSlider();
    metronomeButton = new JToggleButton();

    JLabel metText = new JLabel("Metronome:");
    add(metText);

    ...

    tempoChooser.setMaximum(200);
    tempoChooser.setMinimum(40);
    tempoChooser.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            tempoChooserStateChanged(evt);
        }
    });
    add(tempoChooser);
    ...
    }

private void tempoChooserStateChanged(javax.swing.event.ChangeEvent evt) {
    final int tempo = tempoChooser.getValue();
    if (((JSlider) evt.getSource()).getValueIsAdjusting()) {
        setMetronomeButtonText(tempo);
    } else {
        processTempoChange(tempo);
    }
}

thanks in advance!


Source: (StackOverflow)

Java/Swing Volume Slider

Part of my application has a media component, and I'm looking for a nice volume slider I can use rather than a JSlider which looks a bit ugly for this purpose (or specifically, an extended JSlider with custom visuals would be nice). I could write one, but I don't really want to reinvent the wheel.

In terms of "nice" volume sliders - I'm looking on the lines of something like VLC:

VLC volume slider

Is there a (free) component like this already out there that I'm missing?


Source: (StackOverflow)

Jslider, not appearing on My frame

im trying to make my slider appear on my gui once i run my java project, here is what i >have, any help would be nice :)

so the menu bar appears, the menu shapes appears, and the 3 shapes appear too, i just cant >get the slider to appear on at the bottom of the box


class assignment


package assignment;

public class Assignment {

public static void main(String[] args) {

MyFrame pane = new MyFrame();  

pane.setVisible(true);
pane.setSize(400,400);

class MyFrame


package assignment;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class MyFrame extends javax.swing.JFrame {

/**
 * Creates new form MyFrame
 */
public MyFrame() {
initComponents();

// Create the menu
JMenuBar topMenu = new JMenuBar();
this.setJMenuBar(topMenu);

//create the menu button "shapes"
JMenu shapes = new JMenu("Shapes");
topMenu.add(shapes);
//Create the 3 shapes for the menu
JMenuItem square = new JMenuItem("Square");
JMenuItem circle = new JMenuItem("Circle");        
JMenuItem triangle = new JMenuItem("Triangle");

//add shapes to menu
shapes.add(circle);
shapes.add(triangle);
shapes.add(square);

//add the menu
setJMenuBar(topMenu);


MyControlPanel pane = new MyControlPanel();
this.add(pane);


}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 300, Short.MAX_VALUE)
    );

    pack();
}// </editor-fold>

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

    try {
        for (javax.swing.UIManager.LookAndFeelInfo info :          javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
        new MyFrame().setVisible(true);
        }
    });


}
// Variables declaration - do not modify
// End of variables declaration

}


class MyControlPanel


package assignment;

import javax.swing.JSlider;
import javax.swing.JTextField;


public class MyControlPanel extends javax.swing.JPanel {

/**
 * Creates new form MyControlPanel
 */
public MyControlPanel() {
initComponents();

JSlider slider = new JSlider();
slider.setMajorTickSpacing(10); 
slider.setPaintLabels(true); 
slider.setPaintTicks(true); 

JTextField boundary_length = new JTextField("Boundary Length");
JTextField area = new JTextField("Area");


this.add(slider);
this.add(area);
this.add(boundary_length);

}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 300, Short.MAX_VALUE)
    );
}// </editor-fold>
// Variables declaration - do not modify
// End of variables declaration

}


Source: (StackOverflow)

Change displayable labels for a JSlider?

I have a JSlider with a min of 0 and a max of 10,000. I have the major tick marks set at 1,000. If I were to paint the labels now they would show up as 0, 1000, 2000, 3000, 4000, etc. What I would like to be shown would be 0, 1, 2, 3, 4, 5, etc. What would be a good way to accomplish this task?


Source: (StackOverflow)