jslider

Not getting value from JSlider

穿精又带淫゛_ 提交于 2019-12-11 04:50:52
问题 I am using a JSlider in my program, and have implemented a ChangeListener for the same. public void stateChanged(ChangeEvent e) { JSlider source=(JSlider) e.getSource(); frame_value.setText(Integer.toString(source.getValue())); //Condition to change the frame_no only when user has stopped moving the slider if (!source.getValueIsAdjusting()) { frame_no=(int) source.getValue()-1; if(frame_no<0) frame_no=0; } .... } What is happening is, that whenever the ChangeListener is called, the program

How to set size of a JSlider?

自作多情 提交于 2019-12-10 18:52:56
问题 I have searched the web for a solution to this problem and didn't find anything that worked. I have a vertical JSlider inside a JPanel that uses GridBagLayout and a GridBagConstraints for positioning the objects on the panel. Currently I have the following code: gbc.gridy = 1; add(button1,gbc); gbc.gridy = 2; add(button2,gbc); gbc.gridy = 3; add(slider,gbc); The objects are positioned vertically along the panel. The slider always appears in the same size (length). Tried to use

jSlider go to clicked position - problem only on Macintosh

▼魔方 西西 提交于 2019-12-10 18:26:25
问题 I have been using the above MetalSliderUI solution for all my JSliders. Windows users have been happy with it. I appreciate finding this solution on stackoverflow.com The solution was discussed here: JSlider question: Position after leftclick Now recently a MAC OSX/64bit user is trying to use my software and he gets null pointer exceptions from the MetalSliderUI references. Sample of code which I added to JFrame's constructor: // Radio Window Elecraft K3 RFPWR Slider - when click on slider //

Java Swing Range Slider U.I

為{幸葍}努か 提交于 2019-12-10 17:27:10
问题 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.

How to disable position change of JSlider on mouse right click

只愿长相守 提交于 2019-12-08 04:42:57
问题 I am using a JSlider in my application. I want only left click to slide JSlider , and I want to disable right click for JSlider . I am able to get event on right click, but slider is changing its value to other position. jSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { //code } }); jSlider.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (e.getButton() == java.awt.event.MouseEvent.BUTTON3) { //code } else { //code } }

JSlider for doubles

泄露秘密 提交于 2019-12-06 18:33:19
问题 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 ? 回答1: You can multiply the value by 10 EDIT You can change the labels displayed as follows: Hashtable labelTable = new Hashtable(); labelTable.put( new Integer( 0 ), new JLabel("0.0") );

Overlay multiple JSliders in Swing

旧街凉风 提交于 2019-12-06 11:36:23
Is it possible to overlay multiple JSliders so I can see the "thumbs" on both (I've tried disabling the painting of the track and setting opacity to false but one still hides the other)? Basically I'd like to create a component that allows the user to define a range (and I didn't really want to write a custom one since it has most of the attributes of a slider). If there is another way I could do that with a slider, that would work too. thanks, Jeff Ah, I found it (i must not have been seraching on the right terms). Swing labs as a JXMultiThumbSlider that I think will do the trick. http:/

Change the JSlider look and feel

好久不见. 提交于 2019-12-06 01:39:22
问题 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

JSlider for doubles

…衆ロ難τιáo~ 提交于 2019-12-04 23:45:27
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 ? You can multiply the value by 10 EDIT You can change the labels displayed as follows: Hashtable labelTable = new Hashtable(); labelTable.put( new Integer( 0 ), new JLabel("0.0") ); labelTable.put( new Integer( 5 ), new JLabel("0.5") ); labelTable.put( new Integer( 10 ), new JLabel("1.0") )

Linked JSliders With Maximum Combined Value

倾然丶 夕夏残阳落幕 提交于 2019-12-04 18:24:11
What's the best way to 'link' JSliders to put a cap on the combined value? Imagine a fighting game where the user can specify character traits like speed, agility, endurance and accuracy. The user is given 100 points to allocate however he chooses, but the total value of all the sliders must not exceed 100. That is, the sliders should not allow such increases. If the user has allocated 30 points each to speed, agility and endurance, then the slider for accuracy should allow a maximum of 10 points (because 30 + 30 + 30 + 10 = 100). Notwithstanding, the range of the each slider should remain