Example usage for javax.swing JScrollPane addKeyListener

List of usage examples for javax.swing JScrollPane addKeyListener

Introduction

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

Prototype

public synchronized void addKeyListener(KeyListener l) 

Source Link

Document

Adds the specified key listener to receive key events from this component.

Usage

From source file:org.onebusaway.phone.client.SimplePhoneClient.java

private static void setupGui(AgiClientScriptImpl script) {

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    KeyPressHandler handler = new KeyPressHandler(script);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.addKeyListener(handler);/*from   www.  jav a2s .  co  m*/

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(4, 3));
    panel.add(buttonPanel, BorderLayout.CENTER);

    String buttons = "123456789*0#";

    for (int i = 0; i < buttons.length(); i++)
        addButton(buttonPanel, script, handler, buttons.charAt(i));

    Document document = script.getDocument();

    final JTextArea textArea = new JTextArea(document);
    textArea.setEditable(false);
    textArea.addKeyListener(handler);
    document.addDocumentListener(new ScrollDocumentToEnd(textArea));

    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(300, 100));
    scrollPane.addKeyListener(handler);
    panel.add(scrollPane, BorderLayout.SOUTH);

    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
}