Example usage for javax.swing JScrollBar JScrollBar

List of usage examples for javax.swing JScrollBar JScrollBar

Introduction

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

Prototype

public JScrollBar(int orientation, int value, int extent, int min, int max) 

Source Link

Document

Creates a scrollbar with the specified orientation, value, extent, minimum, and maximum.

Usage

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  ww .  j a va 2 s.  c o 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

public Main() {
    setLayout(new BorderLayout());
    JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 300);
    JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);
    hbar.setUnitIncrement(2);/*  w w  w  . ja  v  a  2 s  . c om*/
    hbar.setBlockIncrement(1);

    hbar.addAdjustmentListener(new MyAdjustmentListener());
    vbar.addAdjustmentListener(new MyAdjustmentListener());

    add(hbar, BorderLayout.SOUTH);
    add(vbar, BorderLayout.EAST);
    add(label, BorderLayout.CENTER);
}

From source file:MainClass.java

public MainClass() {
    super(true);/*www . ja v a 2  s  .co  m*/

    setLayout(new BorderLayout());

    JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 300);
    JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);

    hbar.setUnitIncrement(2);
    hbar.setBlockIncrement(1);

    hbar.addAdjustmentListener(new MyAdjustmentListener());
    vbar.addAdjustmentListener(new MyAdjustmentListener());

    add(hbar, BorderLayout.SOUTH);
    add(vbar, BorderLayout.EAST);
    add(label, BorderLayout.CENTER);
}

From source file:MainClass.java

MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(300, 50));
    JScrollBar jsb;//from w w  w .  j  a v a2 s  .com
    jsb = new JScrollBar(Adjustable.HORIZONTAL, 0, 1, 0, 100);
    jsb.setPreferredSize(new Dimension(200, 20));
    p.add(jsb);

    getContentPane().add(p);

    pack();
    setVisible(true);
}

From source file:SwingScrollBarExample.java

public SwingScrollBarExample() {
    super(true);/*w w w.  ja v a2 s.  c  o  m*/
    label = new JLabel();
    setLayout(new BorderLayout());

    JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 300);
    JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);

    hbar.setUnitIncrement(2);
    hbar.setBlockIncrement(1);

    hbar.addAdjustmentListener(new MyAdjustmentListener());
    vbar.addAdjustmentListener(new MyAdjustmentListener());

    add(hbar, BorderLayout.SOUTH);
    add(vbar, BorderLayout.EAST);
    add(label, BorderLayout.CENTER);
}

From source file:ScrollBarColorSelect.java

public ScrollBarColorSelect() {
    setTitle("ColorSelect");
    setSize(300, 200);/*w ww. ja  v  a 2  s  .  com*/
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = getContentPane();

    JPanel p = new JPanel();
    p.setLayout(new GridLayout(3, 2, 3, 3));

    p.add(redLabel = new JLabel("Red 0"));
    p.add(red = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
    red.setBlockIncrement(16);
    red.addAdjustmentListener(this);

    p.add(greenLabel = new JLabel("Green 0"));
    p.add(green = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
    green.setBlockIncrement(16);
    green.addAdjustmentListener(this);

    p.add(blueLabel = new JLabel("Blue 0"));
    p.add(blue = new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255));
    blue.setBlockIncrement(16);
    blue.addAdjustmentListener(this);

    contentPane.add(p, "South");

    colorPanel = new JPanel();
    colorPanel.setBackground(new Color(0, 0, 0));
    contentPane.add(colorPanel, "Center");
}

From source file:com.googlecode.logVisualizer.chart.turnrundownGantt.GanttChartBuilder.java

@Override
protected void addChart() {
    super.addChart();

    final int scrollCaretExtend = 20;
    int scrollableAreaIntervals = ((TurnRundownDataset) dataset.getUnderlyingDataset()).getDataset().size()
            - (dataset.getMaximumCategoryCount() - scrollCaretExtend);
    scrollableAreaIntervals = scrollableAreaIntervals > 20 ? scrollableAreaIntervals : 20;
    final JScrollBar scrollBar = new JScrollBar(JScrollBar.VERTICAL, 0, scrollCaretExtend, 0,
            scrollableAreaIntervals);/*from  w w  w  . j  ava2 s. c om*/
    scrollBar.getModel().addChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent e) {
            dataset.setFirstCategoryIndex(scrollBar.getValue());
        }
    });

    add(scrollBar, BorderLayout.EAST);
}

From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java

/**
 * @return the verticalScroll/*  ww  w  .  java  2  s.c o m*/
 */
private JScrollBar getVerticalScroll() {
    if (verticalScroll == null) {
        verticalScroll = new JScrollBar(JScrollBar.VERTICAL, 0, 100, 0, 100);
        verticalScroll.getModel().addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent arg0) {
                if (dataset.getColumnCount() > 0) {
                    dataset.setFirstCategoryIndex(verticalScroll.getValue());
                }
            }

        });
    }
    return verticalScroll;
}

From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java

/**
 * @return the horizontalScroll//w w w  .ja va 2 s. c o  m
 */
private JScrollBar getHorizontalScroll() {
    if (horizontalScroll == null) {
        horizontalScroll = new JScrollBar(JScrollBar.HORIZONTAL, 0, DEFAULT_TIMELINE, 0, DEFAULT_TIMELINE);
        horizontalScroll.getModel().addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent arg0) {
                int scrollStart = horizontalScroll.getValue();
                int scrollEnd = scrollStart + horizontalScroll.getVisibleAmount();

                //logger.log(Level.FINE, "Change Event: Setting time range to {0} - {1}", new Object[] {scrollStart, scrollEnd});
                // Set time axis range based on scroll bar new position 
                timeAxis.setRange(scrollStart, scrollEnd);
            }
        });
    }
    return horizontalScroll;
}