Example usage for javax.swing JTextPane getSelectedText

List of usage examples for javax.swing JTextPane getSelectedText

Introduction

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

Prototype

@BeanProperty(bound = false)
public String getSelectedText() 

Source Link

Document

Returns the selected text contained in this TextComponent.

Usage

From source file:Main.java

public static void main(String[] args) {
    JTextPane jTextPane = new JTextPane();
    JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.pack();/*from   w  ww. jav  a2  s  .c o m*/
    frame.setVisible(true);

    JButton btnGetSelectedText = new JButton("Get selected text");
    btnGetSelectedText.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println(jTextPane.getSelectedText());
        }
    });
    frame.getContentPane().add(jTextPane, BorderLayout.NORTH);
    frame.getContentPane().add(btnGetSelectedText, BorderLayout.SOUTH);
}