Example usage for javax.swing JSlider addPropertyChangeListener

List of usage examples for javax.swing JSlider addPropertyChangeListener

Introduction

In this page you can find the example usage for javax.swing JSlider addPropertyChangeListener.

Prototype

public void addPropertyChangeListener(PropertyChangeListener listener) 

Source Link

Document

Adds a PropertyChangeListener to the listener list.

Usage

From source file:at.becast.youploader.gui.FrmMain.java

public void initQueuetab() {
    JScrollPane TabQueues = new JScrollPane();
    QueuePanel = new JPanel();
    TabQueues.setViewportView(QueuePanel);

    QueuePanel.setLayout(new MigLayout("", "[875px,grow,fill]", "[][][][]"));
    JPanel buttonPanel = new JPanel();
    GridBagConstraints gbc_panel_2 = new GridBagConstraints();
    gbc_panel_2.fill = GridBagConstraints.BOTH;
    gbc_panel_2.gridx = 0;//from www . j  a v  a2s  .  co  m
    gbc_panel_2.gridy = 1;
    buttonPanel.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC,
            FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
            FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
            FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
            FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
            FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
            FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(39dlu;default)"),
            FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
            FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(92dlu;default)"),
            FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(46dlu;min)"), FormSpecs.RELATED_GAP_COLSPEC,
            ColumnSpec.decode("left:max(22dlu;default)"), FormSpecs.RELATED_GAP_COLSPEC,
            FormSpecs.DEFAULT_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    RowSpec.decode("max(0dlu;default)"), }));

    JButton btnStart = new JButton(LANG.getString("frmMain.start"));
    btnStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            startUploads();
        }
    });

    JLabel lblAfterUploadsFinish = new JLabel(LANG.getString("frmMain.afterfinish"));
    buttonPanel.add(lblAfterUploadsFinish, "10, 2, 7, 1");
    buttonPanel.add(btnStart, "2, 4");

    JButton btnStop = new JButton(LANG.getString("frmMain.stop"));
    btnStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UploadMgr.stop();
        }
    });
    buttonPanel.add(btnStop, "6, 4");

    cmbAfterFinish = new JComboBox<Object>();
    cmbAfterFinish.setModel(new DefaultComboBoxModel<Object>(new String[] {
            LANG.getString("frmMain.afterfinish.donothing"), LANG.getString("frmMain.afterfinish.suspend"),
            LANG.getString("frmMain.afterfinish.shutdown") }));
    buttonPanel.add(cmbAfterFinish, "10, 4, 7, 1, fill, default");

    JLabel lblUploads = new JLabel(LANG.getString("frmMain.uploads") + ":");
    buttonPanel.add(lblUploads, "18, 4, right, fill");

    JSlider slider = new JSlider();
    slider.setPaintTicks(true);
    slider.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            JSlider s = (JSlider) evt.getSource();
            UploadMgr.setUploadlimit(s.getValue());
        }
    });
    slider.setMajorTickSpacing(1);
    slider.setMinorTickSpacing(1);

    slider.setMinimum(1);
    slider.setMaximum(5);
    slider.setValue(1);
    slider.setSnapToTicks(true);
    slider.setPaintLabels(true);
    buttonPanel.add(slider, "20, 4, fill, fill");

    JLabel lblUploadSpeed = new JLabel(LANG.getString("frmMain.uploadspeed") + ":");
    lblUploadSpeed.setHorizontalAlignment(SwingConstants.TRAILING);
    buttonPanel.add(lblUploadSpeed, "24, 4");

    spinner = new JSpinner();
    spinner.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(10)));
    spinner.setEditor(new SpeedValuesSpinnerEditor(spinner));
    spinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner s = (JSpinner) e.getSource();
            speed = Integer.parseInt(s.getValue().toString());
            Main.s.put("speed", String.valueOf(speed));
            UploadMgr.setLimit(speed);
        }
    });
    spinner.setValue(speed);
    buttonPanel.add(spinner, "26, 4");

    JLabel lblKbps = new JLabel("kbps");
    buttonPanel.add(lblKbps, "28, 4");

    JPanel TabQueue = new JPanel();
    TabbedPane.addTab(LANG.getString("frmMain.Tabs.Queue"), null, TabQueue, null);
    TabQueue.setLayout(new BorderLayout(0, 0));

    TabQueue.add(buttonPanel, BorderLayout.SOUTH);

    TabQueue.add(TabQueues, BorderLayout.CENTER);
}