Hello guys i am writing a simple gui editor in java swing using JTextArea. but now i want to be able to right click and have the options to cut, copy, paste and select all and possibly change fonts. I need help in implementing the option of cutting, copying or pasting in the JTextArea. Help will be appreciated.
Below is a snippet of my code:
public class Example extends JPanel
{
private JTextArea area;
private JScrollPane scpane;
public Example()
{
super("My Text Editor");
setUp();
}
private void setUp()
{
area = new JTextArea();
scpane= new JScrollPane(area);
area.addMouseListener(
new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
if(e.getButton()==MouseEvent.BUTTON3)
{
//having difficulty how to set up the copy, cut or paste option
//with the mouse in JTextArea.
}
}
});
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…