Example usage for javax.swing JScrollPane getHorizontalScrollBar

List of usage examples for javax.swing JScrollPane getHorizontalScrollBar

Introduction

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

Prototype

@Transient
public JScrollBar getHorizontalScrollBar() 

Source Link

Document

Returns the horizontal scroll bar that controls the viewport's horizontal view position.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextArea textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea);

    // Listen for value changes in the scroll pane's scrollbars
    AdjustmentListener listener = new MyAdjustmentListener();
    pane.getHorizontalScrollBar().addAdjustmentListener(listener);
    pane.getVerticalScrollBar().addAdjustmentListener(listener);
}

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);/*from w w  w .  j av a2 s  . 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) throws UnsupportedEncodingException {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    JPanel buttons = new JPanel();
    JScrollPane pane = new JScrollPane(buttons);
    pane.getViewport().addChangeListener(e -> {
        System.out.println("Change in " + e.getSource());
        System.out.println("Vertical visible? " + pane.getVerticalScrollBar().isVisible());
        System.out.println("Horizontal visible? " + pane.getHorizontalScrollBar().isVisible());
    });//from  ww  w  . j a  va2 s  .c  o  m
    panel.add(pane);
    frame.setContentPane(panel);
    frame.setSize(300, 200);
    frame.setVisible(true);
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            for (int i = 0; i < 10; i++) {
                Thread.sleep(800);
                buttons.add(new JButton("Hello " + i));
                buttons.revalidate();
            }
            return null;
        }
    };
    worker.execute();
}

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);//  www. j a va2  s. 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: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);// ww  w  .j  a v  a2 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

/**
 * Scrolls scroll pane to the top left corner.
 *///from   w ww . ja v  a2  s  .  co m
public static void scrollToTop(final JScrollPane scrollPane) {
    JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
    JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar();
    verticalScrollBar.setValue(verticalScrollBar.getMinimum());
    horizontalScrollBar.setValue(horizontalScrollBar.getMinimum());
}

From source file:Main.java

/**
 * @return the visible size of a component in its viewport (including
 *         scrollbars)//  ww  w.  ja  v a  2 s.com
 */
public static Dimension getVisibleSizeInViewport(Component c) {
    if (c.getParent() instanceof JViewport) {
        JViewport vp = (JViewport) c.getParent();
        Dimension d = vp.getExtentSize();
        if (vp.getParent() instanceof JScrollPane) {
            JScrollPane sp = (JScrollPane) vp.getParent();
            if (sp.getVerticalScrollBar() != null && sp.getVerticalScrollBar().isVisible()) {
                d.width += sp.getVerticalScrollBar().getWidth();
            }
            if (sp.getHorizontalScrollBar() != null && sp.getHorizontalScrollBar().isVisible()) {
                d.height += sp.getHorizontalScrollBar().getHeight();
            }
        }
        return d;
    } else {
        return null;
    }
}

From source file:Main.java

public Main() {
    JTextField textField = new JTextField("A TextField");
    textField.addFocusListener(this);
    JLabel label = new JLabel("A Label");
    label.addFocusListener(this);
    add(label);/*w w w . j av a2  s .c om*/

    String comboPrefix = "Item #";
    final int numItems = 15;
    Vector vector = new Vector(numItems);
    for (int i = 0; i < numItems; i++) {
        vector.addElement(comboPrefix + i);
    }
    JComboBox comboBox = new JComboBox(vector);
    comboBox.addFocusListener(this);
    add(comboBox);

    JButton button = new JButton("A Button");
    button.addFocusListener(this);
    add(button);

    JList list = new JList(vector);
    list.setSelectedIndex(1);
    list.addFocusListener(this);
    JScrollPane listScrollPane = new JScrollPane(list);

    listScrollPane.getVerticalScrollBar().setFocusable(false);
    listScrollPane.getHorizontalScrollBar().setFocusable(false);
    add(listScrollPane);

    setPreferredSize(new Dimension(450, 450));
}

From source file:Main.java

public Main() {
    JTextField textField = new JTextField("A TextField");
    textField.addFocusListener(this);
    JLabel label = new JLabel("A Label");
    label.addFocusListener(this);
    add(label);/*from  ww w .j a v  a 2 s.co m*/

    String comboPrefix = "ComboBox Item #";
    final int numItems = 15;
    Vector vector = new Vector(numItems);
    for (int i = 0; i < numItems; i++) {
        vector.addElement(comboPrefix + i);
    }
    JComboBox comboBox = new JComboBox(vector);
    comboBox.addFocusListener(this);
    add(comboBox);

    JButton button = new JButton("A Button");
    button.addFocusListener(this);
    add(button);

    String listPrefix = "List Item #";
    Vector listVector = new Vector(numItems);
    for (int i = 0; i < numItems; i++) {
        listVector.addElement(listPrefix + i);
    }
    JList list = new JList(listVector);
    list.setSelectedIndex(1);
    list.addFocusListener(this);
    JScrollPane listScrollPane = new JScrollPane(list);

    listScrollPane.getVerticalScrollBar().setFocusable(false);
    listScrollPane.getHorizontalScrollBar().setFocusable(false);
    add(listScrollPane);

    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:fuel.gui.stats.MotorStatsPanel.java

public MotorStatsPanel(Database database) throws SQLException {
    this.database = database;
    controller = new Controller();
    JPanel container = new JPanel(new BorderLayout());
    //container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
    JPanel motorSelectionPanel = new JPanel();
    motorSelectionPanel.setLayout(new BoxLayout(motorSelectionPanel, BoxLayout.X_AXIS));
    motorSpecsPanel = new JPanel(new GridLayout(2, 3));
    motorSpecsPanel.setBorder(BorderFactory.createTitledBorder("Specs"));
    graphContainer = new JPanel();
    graphContainer.setLayout(new BoxLayout(graphContainer, BoxLayout.Y_AXIS));
    JComboBox motorSelector = new JComboBox(database.getMotorcycles().toArray());
    motorSelector.setActionCommand("SELECTMOTOR");
    motorSelector.addActionListener(controller);
    motorSelectionPanel.add(motorSelector);

    //motorSelector.setSelectedIndex(0);

    motorSelectionPanel.add(motorSpecsPanel);
    refreshMotorSpecs((Motorcycle) motorSelector.getSelectedItem());

    container.add(motorSelectionPanel, BorderLayout.NORTH);
    JScrollPane scroll = new JScrollPane(graphContainer);
    scroll.getHorizontalScrollBar().setUnitIncrement(10);
    scroll.getVerticalScrollBar().setUnitIncrement(10);
    container.add(scroll, BorderLayout.CENTER);

    refreshGraphs((Motorcycle) motorSelector.getSelectedItem());
    setLayout(new BorderLayout());
    add(container);// w  w w .j  a v a 2  s  .  c  om

    setVisible(true);
}