List of usage examples for javax.swing JTextPane selectAll
public void selectAll()
TextComponent
. From source file:Main.java
public static void main(String[] args) { final JTextPane tp = new JTextPane(); JButton withFocus = new JButton("Select with focus"); withFocus.addActionListener(e -> { tp.selectAll(); tp.requestFocus();// ww w . j a v a 2 s .c o m }); JButton withOutFocus = new JButton("Select without focus"); withFocus.addActionListener(e -> tp.selectAll()); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(tp)); JPanel panel = new JPanel(); panel.add(withFocus); panel.add(withOutFocus); frame.add(panel, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JTextPane tp = new JTextPane(); JButton withFocus = new JButton("Select with focus"); tp.addMouseListener(new MouseAdapter() { @Override/*from www .ja v a2 s .c o m*/ public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) { tp.selectAll(); } } }); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(tp)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }