List of usage examples for javax.swing JTextPane requestFocus
public void requestFocus()
Component
gets the input focus. 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();/* w w w. java2 s . c om*/ tp.requestFocus(); }); 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); }