I am to make a cut and a replace method on JTextArea. I have the code for copy and paste, and I reckon I could just use that, in addition to just deleting the marked text in the JTA.
How would the code for a code for cut and replace methods look like?
The code for copy looks like this:
public void copy(){
int start=ta.getSelectionStart();
int end=ta.getSelectionEnd();
String s=ta.getText();
aString=s.substring(start,end);
System.out.println(aString);
}
And the paste code looks like the following:
public void paste(){
int start=ta.getSelectionStart();
String startText=ta.getText().substring(0, start);
String endText=ta.getText().substring(start);
String res=startText+clipBoard+endText;
ta.setText(res);
}
So basically: How do I delete marked text in a JTextArea? Or is there possibly a better way to do this?