I am making a code editor in Java and I have used RSyntaxTextArea
jar file to take help.
The problem is - There is a ComboBox
in application with which we can switch languages. There are two methods in RSyntaxTextArea
: setSyntaxEditingStyle()
and getSyntaxEditingStyle()
which are not working inside ComboBox
action listener. Please help me, I am badly stuck. Here is the code. Both the methods:
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
and
String a = textArea.getSyntaxEditingStyle();
are not working inside Action Event function. They work perfectly outside but there is no way to use it outside.
public void actionPerformed(ActionEvent e) {
if ( language == "Python") {
try {
textArea.setSyntaxEditingStyle(null);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON);
textArea.getSyntaxEditingStyle();
String command = "python " + opened_file;
Runtime.getRuntime().exec("cmd /c start cmd.exe /K " + command);
} catch (IOException e5) {
e5.printStackTrace();
}
}
else if (language == "Java") {
try {
// Look Here
// Look Here
// Look Here
// Look Here
// Look Here
// Look Here
// Look Here
// Look Here
// Look Here {
textArea
.setSyntaxEditingStyle(
SyntaxConstants.SYNTAX_STYLE_JAVA
);
String a = textArea.getSyntaxEditingStyle();
System.out.println(a);
// Look Here }
// Look Here
// Look Here
// Look Here
// Look Here
// Look Here
// Look Here
// Look Here
String classpath = opened_file.replace(".java", "");
String [] last_name_list = opened_file.split("\\\\");
String lastname = last_name_list[last_name_list.length - 1];
String folderpath = opened_file.replace(lastname, "");
String []classpath_1 = classpath.split("\\\\");
String class_file = classpath_1[classpath_1.length-1];
Runtime rt = Runtime.getRuntime();
rt.exec("cmd /c start cmd.exe /K \"cd " + folderpath + " && javac " + opened_file + " && java " + class_file +"\"");
}catch (Exception e5) {
e5.printStackTrace();
}
}