Example usage for java.awt.event AdjustmentListener AdjustmentListener

List of usage examples for java.awt.event AdjustmentListener AdjustmentListener

Introduction

In this page you can find the example usage for java.awt.event AdjustmentListener AdjustmentListener.

Prototype

AdjustmentListener

Source Link

Usage

From source file:ScrollBarSample.java

public static void main(String args[]) {
    AdjustmentListener adjustmentListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) {
            System.out.println("Adjusted: " + adjustmentEvent.getValue());
        }/*from   www .j a va  2s  . c  o m*/
    };
    JScrollBar oneJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
    oneJScrollBar.addAdjustmentListener(adjustmentListener);

    JFrame frame = new JFrame("ScrollBars R Us");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(oneJScrollBar, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    AdjustmentListener adjustmentListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) {
            System.out.println("Adjusted: " + adjustmentEvent.getValue());
        }//from w w w . j a v  a2 s .  com
    };
    JScrollBar oneJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
    oneJScrollBar.addAdjustmentListener(adjustmentListener);

    JFrame frame = new JFrame("ScrollBars R Us");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(oneJScrollBar, BorderLayout.NORTH);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    JTextArea b = new JTextArea();
    b.setPreferredSize(new Dimension(600, 600));
    JScrollPane pane = new JScrollPane(b);
    AdjustmentListener hListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Horizontal: ");
            dumpInfo(e);// w w  w  .  ja  v a  2s. c  o  m
        }
    };
    JScrollBar hBar = pane.getHorizontalScrollBar();
    hBar.addAdjustmentListener(hListener);
    AdjustmentListener vListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Vertical: ");
            dumpInfo(e);
        }
    };
    JScrollBar vBar = pane.getVerticalScrollBar();
    vBar.addAdjustmentListener(vListener);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    Icon icon = new ImageIcon("java2s.gif");
    JButton b = new JButton(icon);
    JScrollPane pane = new JScrollPane(b);
    AdjustmentListener hListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Horizontal: ");
            dumpInfo(e);//from w w w  . j av  a 2 s.com
        }
    };
    JScrollBar hBar = pane.getHorizontalScrollBar();
    hBar.addAdjustmentListener(hListener);
    AdjustmentListener vListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Vertical: ");
            dumpInfo(e);
        }
    };
    JScrollBar vBar = pane.getVerticalScrollBar();
    vBar.addAdjustmentListener(vListener);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:AdjustmentTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    Icon icon = new ImageIcon("java2s.gif");
    JButton b = new JButton(icon);
    JScrollPane pane = new JScrollPane(b);
    AdjustmentListener hListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Horizontal: ");
            dumpInfo(e);//w  w  w  .j  a  v a 2  s . com
        }
    };
    JScrollBar hBar = pane.getHorizontalScrollBar();
    hBar.addAdjustmentListener(hListener);
    AdjustmentListener vListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Vertical: ");
            dumpInfo(e);
        }
    };
    JScrollBar vBar = pane.getVerticalScrollBar();
    vBar.addAdjustmentListener(vListener);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.show();
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();

    JPanel main = new JPanel(new GridLayout(2, 1));
    JPanel scrollBarPanel = new JPanel();
    final JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 48, 0, 255);
    int height = scrollBar.getPreferredSize().height;
    scrollBar.setPreferredSize(new Dimension(175, height));
    scrollBarPanel.add(scrollBar);//  w  w w  .  j a v a  2  s .  co m
    main.add(scrollBarPanel);

    JPanel sliderPanel = new JPanel();
    final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 255, 128);
    slider.setMajorTickSpacing(48);
    slider.setMinorTickSpacing(16);
    slider.setPaintTicks(true);
    sliderPanel.add(slider);
    main.add(sliderPanel);

    frame.add(main, BorderLayout.CENTER);

    scrollBar.addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("JScrollBar's current value = " + scrollBar.getValue());
        }
    });

    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            System.out.println("JSlider's current value = " + slider.getValue());
        }
    });

    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

Main() {
    JFrame f = new JFrame();
    f.setLayout(new FlowLayout());
    f.setSize(280, 300);/*www .  jav a  2s .co  m*/
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    scrollBarVertical.setPreferredSize(new Dimension(20, 200));
    scrollbarHorizontal.setPreferredSize(new Dimension(200, 20));

    scrollbarHorizontal.setValue(50);

    scrollBarVertical.addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent ae) {
            if (scrollBarVertical.getValueIsAdjusting())
                return;
            System.out.println("Value of vertical scroll bar: " + ae.getValue());
        }
    });

    scrollbarHorizontal.addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent ae) {
            System.out.println("Value of horizontal scroll bar: " + ae.getValue());
        }
    });

    f.add(scrollBarVertical);
    f.add(scrollbarHorizontal);

    f.setVisible(true);
}

From source file:CustomScrollPane.java

public CustomScrollPane(JComponent comp) {
    setLayout(null);/*from   w  ww .  j  a v  a2s .c om*/

    add(viewport);
    innerComponent = comp;
    viewport.add(innerComponent);

    verticalBar.setUnitIncrement(5);
    add(verticalBar);

    horizontalBar.setUnitIncrement(5);
    add(horizontalBar);

    AdjustmentListener lst = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            viewport.doLayout();
        }
    };
    verticalBar.addAdjustmentListener(lst);
    horizontalBar.addAdjustmentListener(lst);
}

From source file:org.fhaes.FHRecorder.FireHistoryRecorder.java

private void initComponents() {

    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {

            closeAfterRunningChecks();//from w  w  w .  ja  v a 2 s .  co m

        }

    });

    setMinimumSize(new java.awt.Dimension(950, 675));
    setResizable(true);

    getContentPane().setLayout(new MigLayout("", "[810px,grow]", "[466.00,grow][42.00]"));

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    getContentPane().add(tabbedPane, "cell 0 0,grow");

    sampleInputHolder = new JPanel();
    siteInfoHolder = new JPanel();

    sampleInputHolder.setLayout(new BorderLayout());
    siteInfoHolder.setLayout(new BorderLayout());

    tabbedPane.addTab("Data", null, sampleInputHolder, null);
    tabbedPane.addTab("Metadata", null, siteInfoHolder, null);

    summaryHolder = new JPanel();
    tabbedPane.addTab("Summary", null, summaryHolder, null);

    graphicsHolder = new JPanel();
    tabbedPane.addTab("Graphics", null, graphicsHolder, null);
    graphicsHolder.setLayout(new BorderLayout(0, 0));

    chartScrollBar = new JScrollBar();
    chartScrollBar.setMaximum(110);
    chartScrollBar.addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent arg0) {
            if (graphicsPanel != null) {
                graphicsPanel.updateVisibleYears(chartScrollBar.getValue());
            }
        }
    });
    chartScrollBar.setOrientation(JScrollBar.HORIZONTAL);
    graphicsHolder.add(chartScrollBar, BorderLayout.SOUTH);

    fileErrorHolder = new JPanel();
    tabbedPane.addTab("File Errors", null, fileErrorHolder, null);

    panelButtonBar = new JPanel();
    getContentPane().add(panelButtonBar, "cell 0 1,alignx right,growy");

    useLimitsCheckBox = new JCheckBox("Keep FHX2 Limitations");
    panelButtonBar.add(useLimitsCheckBox);
    useLimitsCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            siteInfo.setLimitRestriction(useLimitsCheckBox.isSelected());
        }
    });

    btnSave = new JButton("Save");
    panelButtonBar.add(btnSave);
    btnSave.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            saveMenuItemActionPerformed(e);
        }

    });

    btnClose = new JButton("Close");
    btnClose.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            closeAfterRunningChecks();
        }

    });
    panelButtonBar.add(btnClose);

    btnCancel = new JButton("Discard changes");
    panelButtonBar.add(btnCancel);
    btnCancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            Controller.filePath = null;
            setVisible(false);

        }

    });

    pack();
}

From source file:edu.pdi2.visual.ThresholdSignature.java

private void initGUI(int cantBands) {
    try {//from w  ww.  j a v  a2 s.c o  m
        {
            getContentPane().setLayout(null);
            this.setPreferredSize(new java.awt.Dimension(359, 457));
            {
                for (int i = 0; i < cantBands; ++i) {
                    scrollbars[i] = new JScrollBar();
                    getContentPane().add(scrollbars[i]);
                    scrollbars[i].setBounds(50 * i + 20, 42, 17, 71);
                    scrollbars[i].setValue(INITIAL_DEVIATION);

                    final Integer index = new Integer(i);
                    scrollbars[i].addAdjustmentListener(new AdjustmentListener() {
                        public void adjustmentValueChanged(AdjustmentEvent evt) {
                            evt.setSource(new Integer(index));
                            scrollBarAdjustmentValueChanged(evt);
                        }

                    });

                }
            }
            // {
            // jScrollBar1 = new JScrollBar();
            // getContentPane().add(jScrollBar1);
            // jScrollBar1.setBounds(20, 42, 17, 71);
            // jScrollBar1.addAdjustmentListener(new AdjustmentListener() {
            // public void adjustmentValueChanged(AdjustmentEvent evt) {
            // jScrollBar1AdjustmentValueChanged(evt);
            // }
            // });
            // }
            {
                for (int i = 0; i < cantBands; ++i) {
                    bandLabels[i] = new JLabel();
                    getContentPane().add(bandLabels[i]);
                    bandLabels[i].setText("Band " + i);
                    bandLabels[i].setBounds(50 * i + 12, 23, 33, 14);

                }
            }

            // {
            // jLabel1 = new JLabel();
            // getContentPane().add(jLabel1);
            // jLabel1.setText("Band 1");
            // jLabel1.setBounds(12, 23, 33, 14);
            // }
            {
                signatureG = ChartFactory.createXYLineChart("Signature ", "Bands", "Valory", null,
                        PlotOrientation.VERTICAL, true, true, false);
                chartpanel = new ChartPanel(signatureG);
                getContentPane().add(chartpanel);
                chartpanel.setBorder(BorderFactory.createTitledBorder(""));
                chartpanel.setBounds(20, 157, 45 * cantBands + 20, 210);
            }
            // {
            // jLabel2 = new JLabel();
            // getContentPane().add(jLabel2);
            // jLabel2.setText("Band 2");
            // jLabel2.setBounds(62, 23, 33, 14);
            // }
            // {
            // jScrollBar2 = new JScrollBar();
            // getContentPane().add(jScrollBar2);
            // jScrollBar2.setBounds(70, 42, 17, 71);
            // jScrollBar2.addAdjustmentListener(new AdjustmentListener() {
            // public void adjustmentValueChanged(AdjustmentEvent evt) {
            // jScrollBar2AdjustmentValueChanged(evt);
            // }
            // });
            // }
            // {
            // jLabel3 = new JLabel();
            // getContentPane().add(jLabel3);
            // jLabel3.setText("Band 3");
            // jLabel3.setBounds(112, 23, 33, 14);
            // }
            // {
            // jScrollBar3 = new JScrollBar();
            // getContentPane().add(jScrollBar3);
            // jScrollBar3.setBounds(120, 42, 17, 71);
            // jScrollBar3.addAdjustmentListener(new AdjustmentListener() {
            // public void adjustmentValueChanged(AdjustmentEvent evt) {
            // jScrollBar3AdjustmentValueChanged(evt);
            // }
            // });
            // }
            // {
            // jLabel4 = new JLabel();
            // getContentPane().add(jLabel4);
            // jLabel4.setText("Band 4");
            // jLabel4.setBounds(162, 23, 33, 14);
            // }
            // {
            // jScrollBar4 = new JScrollBar();
            // getContentPane().add(jScrollBar4);
            // jScrollBar4.setBounds(170, 42, 17, 71);
            // jScrollBar4.addAdjustmentListener(new AdjustmentListener() {
            // public void adjustmentValueChanged(AdjustmentEvent evt) {
            // jScrollBar4AdjustmentValueChanged(evt);
            // }
            // });
            // }
            // {
            // jLabel5 = new JLabel();
            // getContentPane().add(jLabel5);
            // jLabel5.setText("Band 5");
            // jLabel5.setBounds(212, 23, 33, 14);
            // }
            // {
            // jScrollBar5 = new JScrollBar();
            // getContentPane().add(jScrollBar5);
            // jScrollBar5.setBounds(220, 42, 17, 71);
            // jScrollBar5.addAdjustmentListener(new AdjustmentListener() {
            // public void adjustmentValueChanged(AdjustmentEvent evt) {
            // jScrollBar5AdjustmentValueChanged(evt);
            // }
            // });
            // }
            // {
            // jLabel6 = new JLabel();
            // getContentPane().add(jLabel6);
            // jLabel6.setText("Band 6");
            // jLabel6.setBounds(262, 23, 33, 14);
            // }
            // {
            // jScrollBar6 = new JScrollBar();
            // getContentPane().add(jScrollBar6);
            // jScrollBar6.setBounds(270, 42, 17, 71);
            // jScrollBar6.addAdjustmentListener(new AdjustmentListener() {
            // public void adjustmentValueChanged(AdjustmentEvent evt) {
            // jScrollBar6AdjustmentValueChanged(evt);
            // }
            // });
            // }
            // {
            // jLabel7 = new JLabel();
            // getContentPane().add(jLabel7);
            // jLabel7.setText("Band 7");
            // jLabel7.setBounds(312, 23, 33, 14);
            // }
            // {
            // jScrollBar7 = new JScrollBar();
            // getContentPane().add(jScrollBar7);
            // jScrollBar7.setBounds(320, 42, 17, 71);
            // jScrollBar7.addAdjustmentListener(new AdjustmentListener() {
            // public void adjustmentValueChanged(AdjustmentEvent evt) {
            // jScrollBar7AdjustmentValueChanged(evt);
            // }
            // });
            // }
            {
                for (int i = 0; i < cantBands; ++i) {
                    valueLabels[i] = new JLabel();
                    getContentPane().add(valueLabels[i]);
                    valueLabels[i].setText(String.valueOf(INITIAL_DEVIATION));
                    valueLabels[i].setBounds(50 * i + 20, 119, 33, 19);

                }
            }
            // {
            // jLabel8 = new JLabel();
            // getContentPane().add(jLabel8);
            // jLabel8.setBounds(20, 119, 33, 19);
            // jLabel8.setText("0");
            // }
            // {
            // jLabel9 = new JLabel();
            // getContentPane().add(jLabel9);
            // jLabel9.setText("0");
            // jLabel9.setBounds(70, 119, 33, 19);
            // }
            // {
            // jLabel10 = new JLabel();
            // getContentPane().add(jLabel10);
            // jLabel10.setText("0");
            // jLabel10.setBounds(120, 119, 33, 19);
            // }
            // {
            // jLabel11 = new JLabel();
            // getContentPane().add(jLabel11);
            // jLabel11.setText("0");
            // jLabel11.setBounds(170, 119, 33, 19);
            // }
            // {
            // jLabel12 = new JLabel();
            // getContentPane().add(jLabel12);
            // jLabel12.setText("0");
            // jLabel12.setBounds(220, 119, 33, 19);
            // }
            // {
            // jLabel13 = new JLabel();
            // getContentPane().add(jLabel13);
            // jLabel13.setText("0");
            // jLabel13.setBounds(270, 119, 33, 19);
            // }
            // {
            // jLabel14 = new JLabel();
            // getContentPane().add(jLabel14);
            // jLabel14.setText("0");
            // jLabel14.setBounds(320, 119, 33, 19);
            // }
            {
                btCancel = new JButton();
                getContentPane().add(btCancel);
                btCancel.setText("Cancel");
                btCancel.setBounds(51 * cantBands - 75, 379, 75, 25);
                btCancel.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent evt) {
                        btCancelMouseClicked(evt);
                    }
                });
            }
            {
                btOk = new JButton();
                getContentPane().add(btOk);
                btOk.setText("Generate");
                btOk.setBounds(51 * cantBands - 155, 379, 75, 25);
                btOk.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent evt) {
                        btOkMouseClicked(evt);
                    }
                });
            }
        }
        this.setSize(51 * cantBands + 40, 457);
        this.setResizable(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
}