Example usage for javax.swing JTextField getScrollOffset

List of usage examples for javax.swing JTextField getScrollOffset

Introduction

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

Prototype

public int getScrollOffset() 

Source Link

Document

Gets the scroll offset, in pixels.

Usage

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Offset Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    final JTextField textField = new JTextField();
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    JButton button = new JButton("Get Offset");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Offset: " + textField.getScrollOffset());
            System.out.println("Visibility: " + textField.getHorizontalVisibility());
            BoundedRangeModel model = textField.getHorizontalVisibility();
            int extent = model.getExtent();
            textField.setScrollOffset(extent);
        }/*from w ww .j a v  a 2 s . co  m*/
    };
    button.addActionListener(actionListener);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);

}

From source file:OffsetSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Offset Example");
    Container content = frame.getContentPane();
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);
    final JTextField textField = new JTextField();
    label.setLabelFor(textField);// ww w .j ava2 s  . c  om
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    content.add(panel, BorderLayout.NORTH);
    JButton button = new JButton("Get Offset");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Offset: " + textField.getScrollOffset());
            System.out.println("Visibility: " + textField.getHorizontalVisibility());
            BoundedRangeModel model = textField.getHorizontalVisibility();
            int extent = model.getExtent();
            textField.setScrollOffset(extent);
        }
    };
    button.addActionListener(actionListener);
    content.add(button, BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);
}