JScrollBar: getMinimum() : JScrollBar « javax.swing « Java by API






JScrollBar: getMinimum()

 

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.border.LineBorder;

public class MainClass {
  public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Cornering Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("+");
    
    JLabel bigLabel = new JLabel("A");
    bigLabel.setPreferredSize(new Dimension(400,400));
    bigLabel.setBorder(new LineBorder(Color.red));
    
    JScrollPane scrollPane = new JScrollPane(bigLabel);
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, button);
    scrollPane.setColumnHeaderView(new JLabel("B"));
    scrollPane.setRowHeaderView(new JLabel("C"));

    ActionListener actionListener = new JScrollPaneToTopAction(scrollPane);
    button.addActionListener(actionListener);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }

}


class JScrollPaneToTopAction implements ActionListener {
  JScrollPane scrollPane;
  public JScrollPaneToTopAction(JScrollPane scrollPane) {
    if (scrollPane == null) {
      throw new IllegalArgumentException("JScrollPaneToTopAction: null JScrollPane");
    }
    this.scrollPane = scrollPane;
  }
  public void actionPerformed(ActionEvent actionEvent) {
    JScrollBar verticalScrollBar   = scrollPane.getVerticalScrollBar();
    JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar();
    verticalScrollBar.setValue(verticalScrollBar.getMinimum());
    horizontalScrollBar.setValue(horizontalScrollBar.getMinimum());
  }
}

           
         
  








Related examples in the same category

1.JScrollBar.HORIZONTAL
2.new JScrollBar(int orientation)
3.new JScrollBar(int orientation, int value, int extent, int min, int max)
4.JScrollBar: addAdjustmentListener(AdjustmentListener l)
5.JScrollBar: getBlockIncrement(int direction)
6.JScrollBar: getModel()
7.JScrollBar: getUnitIncrement(int direction)
8.JScrollBar: setBlockIncrement(int blockIncrement)
9.JScrollBar: setFocusable(boolean focusable)
10.JScrollBar: setUnitIncrement(int unitIncrement)
11.JScrollBar: setValue(int value)