jslider

Using Slider to rotate Object In java

回眸只為那壹抹淺笑 提交于 2019-12-01 11:16:30
I have made a GUI that uses a slider to scale an object up and down.(in this case a rectangle). I was wondering if there was a way to also use a slider to specify a degree of rotation. So there would be 2 sliders one to control scale and another to control the rotation. If anyone could help me make this that would be great here is what I have so far with just the scale slider. import javax.swing.*; public class Parker { public static void main(String[] args) { TheWindow w = new TheWindow(); w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //X wont close the window with out this line w.setSize

Java: link JSlider and JTextfield for float value

隐身守侯 提交于 2019-12-01 06:26:51
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! Here's a quick and dirty demo: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Main { public static void main(String[] args) { final JFrame frame = new JFrame(); final JTextField text = new JTextField(20); final JSlider slider = new JSlider(0, 100, 0); slider.addChangeListener(new ChangeListener(){ @Override public void stateChanged(ChangeEvent e) { text.setText(String.valueOf

Java: link JSlider and JTextfield for float value

﹥>﹥吖頭↗ 提交于 2019-12-01 04:24:22
问题 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! 回答1: Here's a quick and dirty demo: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Main { public static void main(String[] args) { final JFrame frame = new JFrame(); final JTextField text = new JTextField(20); final JSlider slider = new JSlider(0, 100, 0); slider

Set the size of a JSlider thumb

佐手、 提交于 2019-11-29 06:32:51
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: Enabling paintTicks with a major and minor tick spacing of 0 gives a better (although not preferred) display: The desired display is shown in the following image - taken from a native Windows 7 application: You could try customizing the JSlider Look and Feel as follows: UIDefaults defaults = UIManager.getDefaults();

Changing a JLabel's Value from a JSlider's Value

爱⌒轻易说出口 提交于 2019-11-28 14:07:05
I have a single JPanel that contains a JSlider and a JLabel. I want to configure it so that when the JSlider's value is being changed by the user, that new value is reflected by the JLabel. I understand that I can fire ChangeEvents with the Slider, but I don't know how to add a ChangeListener to the JLabel. Here's a snippet of my code. scaleSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { int currentTime = ((JSlider)event.getSource()).getValue(); doSomething(currentTime); fireStateChanged(event); } JLabel timeValue = new JLabel("Time: " +

JSlider question: Position after leftclick

假如想象 提交于 2019-11-28 09:54:30
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? 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

Java JSlider precision problems

北战南征 提交于 2019-11-27 19:25:27
问题 I have a list of N JSliders (N does not change procedurally, only as I add more features. Currently N equals 4). The sum of all the sliders values must equal to 100. As one slider moves the rest of the sliders shall adjust. Each slider has values that range from 0 to 100. Currently I am using this logic when a slider is changed (pseudo-code): newValue = currentSlider.getValue otherSliders = allSliders sans currentSlider othersValue = summation of otherSliders values properOthersValue = 100 -

JButton, JCheckBox and similar interactors do not change visually

北战南征 提交于 2019-11-27 16:16:32
Here is a simple graphics programs which adds some stars on the screen. import acm.graphics.*; import acm.program.*; import java.awt.event.*; import javax.swing.*; /** * This program creates a five-pointed star every time the * user clicks the mouse on the canvas. */ public class DrawStarMap1 extends GraphicsProgram { public void init() { /* Initializes the mouse listeners */ addMouseListeners(); /* The check box starts out in the "on" position */ fillCheckBox = new JCheckBox("Filled"); fillCheckBox.setSelected(true); add(fillCheckBox, SOUTH); /* Clears the screen with a button */ add(new

Changing a JLabel's Value from a JSlider's Value

会有一股神秘感。 提交于 2019-11-27 08:04:16
问题 I have a single JPanel that contains a JSlider and a JLabel. I want to configure it so that when the JSlider's value is being changed by the user, that new value is reflected by the JLabel. I understand that I can fire ChangeEvents with the Slider, but I don't know how to add a ChangeListener to the JLabel. Here's a snippet of my code. scaleSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { int currentTime = ((JSlider)event.getSource()).getValue();

JSlider question: Position after leftclick

柔情痞子 提交于 2019-11-27 03:17:58
问题 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: 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