List of usage examples for javax.swing JTextPane getSelectedText
@BeanProperty(bound = false)
public String getSelectedText()
TextComponent
. 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); }