Changeset 26 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/gui/drawers/RangeSliderDemo.java
- Timestamp:
- 07/29/2017 02:22:14 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/scriptbuilder/gui/drawers/RangeSliderDemo.java
r25 r26 1 package scriptbuilder.gui.drawers; 1 2 2 3 import java.awt.BorderLayout; … … 14 15 import javax.swing.event.ChangeEvent; 15 16 import javax.swing.event.ChangeListener; 17 16 18 /* 17 19 The MIT License … … 36 38 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 37 39 THE SOFTWARE. 38 */40 */ 39 41 40 42 /** 41 43 * Demo application panel to display a range slider. 42 44 */ 43 public class RangeSliderDemo extends JPanel { 45 public class RangeSliderDemo extends JPanel 46 { 44 47 45 48 private JLabel rangeSliderLabel1 = new JLabel(); … … 49 52 private RangeSlider rangeSlider = new RangeSlider(); 50 53 51 public RangeSliderDemo() { 54 public RangeSliderDemo() 55 { 52 56 setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); 53 57 setLayout(new GridBagLayout()); 54 58 55 59 rangeSliderLabel1.setText("Lower value:"); 56 60 rangeSliderLabel2.setText("Upper value:"); 57 61 rangeSliderValue1.setHorizontalAlignment(JLabel.LEFT); 58 62 rangeSliderValue2.setHorizontalAlignment(JLabel.LEFT); 59 63 60 64 rangeSlider.setPreferredSize(new Dimension(240, rangeSlider.getPreferredSize().height)); 61 65 rangeSlider.setMinimum(0); 62 66 rangeSlider.setMaximum(10); 63 67 64 68 // Add listener to update display. 65 rangeSlider.addChangeListener(new ChangeListener() { 66 public void stateChanged(ChangeEvent e) { 69 rangeSlider.addChangeListener(new ChangeListener() 70 { 71 public void stateChanged(ChangeEvent e) 72 { 67 73 RangeSlider slider = (RangeSlider) e.getSource(); 68 74 rangeSliderValue1.setText(String.valueOf(slider.getValue())); … … 72 78 73 79 add(rangeSliderLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 74 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0));80 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0)); 75 81 add(rangeSliderValue1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 76 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 0), 0, 0));82 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 0), 0, 0)); 77 83 add(rangeSliderLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 78 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0));84 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0)); 79 85 add(rangeSliderValue2, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 80 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 6, 0), 0, 0));81 add(rangeSlider , new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0,82 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));86 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 6, 0), 0, 0)); 87 add(rangeSlider, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0, 88 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); 83 89 } 84 85 public void display() { 90 91 public void display() 92 { 86 93 // Initialize values. 87 94 rangeSlider.setValue(3); 88 95 rangeSlider.setUpperValue(7); 89 96 90 97 // Initialize value display. 91 98 rangeSliderValue1.setText(String.valueOf(rangeSlider.getValue())); 92 99 rangeSliderValue2.setText(String.valueOf(rangeSlider.getUpperValue())); 93 100 94 101 // Create window frame. 95 102 JFrame frame = new JFrame(); … … 97 104 frame.setResizable(false); 98 105 frame.setTitle("Range Slider Demo"); 99 106 100 107 // Set window content and validate. 101 108 frame.getContentPane().setLayout(new BorderLayout()); 102 109 frame.getContentPane().add(this, BorderLayout.CENTER); 103 110 frame.pack(); 104 111 105 112 // Set window location and display. 106 113 frame.setLocationRelativeTo(null); 107 114 frame.setVisible(true); 108 115 } 109 116 110 117 /** 111 118 * Main application method. 119 * 112 120 * @param args String[] 113 121 */ 114 public static void main(String[] args) { 115 try { 122 public static void main(String[] args) 123 { 124 try 125 { 116 126 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 117 } catch (Exception ex) { 127 } 128 catch (Exception ex) 129 { 118 130 ex.printStackTrace(); 119 131 } 120 132 121 SwingUtilities.invokeLater(new Runnable() { 122 public void run() { 133 SwingUtilities.invokeLater(new Runnable() 134 { 135 public void run() 136 { 123 137 new RangeSliderDemo().display(); 124 138 }
Note: See TracChangeset
for help on using the changeset viewer.
