简体   繁体   English

Groovy 类路径问题

[英]Groovy classpath issue

I have run the following code in this page RsyntaxTextArea using Java and i run the program exactly the way that is been mentioned in this site.And i'm getting the output as intended.我已经使用 Java 在此页面RsyntaxTextArea中运行了以下代码,并且我完全按照本网站中提到的方式运行了该程序。我按预期获得了 output。 But i have tried to modify this java code to Groovy code, something like:但是我尝试将此 java 代码修改为 Groovy 代码,例如:

import groovy.swing.SwingBuilder
import javax.swing.*
import java.awt.*
swing =  new SwingBuilder()
frame = swing.frame(title : "test", defaultCloseOperation:JFrame.EXIT_ON_CLOSE, pack:true, show : true, size :[100,100])
{
        panel
        {
             RSyntaxTextArea textArea = new RSyntaxTextArea();
             textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
        }
}

And when i try to run this script as follows:当我尝试按如下方式运行此脚本时:

groovyc -classpath rsyntaxtextarea.jar TextEditorDemo.groovy 

I get the errors stating that:我收到错误说明:

groovy: 9: unable to resolve class RSyntaxTextArea 
 @ line 9, column 19.
        RSyntaxTextArea textArea = new RSyntaxTextArea();
                     ^

/home/anto/Groovy/Rsyntax/ST.groovy: 9: unable to resolve class RSyntaxTextArea 
 @ line 9, column 30.
        RSyntaxTextArea textArea = new RSyntaxTextArea();
                                ^

/home/anto/Groovy/Rsyntax/ST.groovy: 10: unable to resolve class RSyntaxTextArea 
 @ line 10, column 7.
         textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);

I guess i have made wrong in running the program.我想我在运行程序时犯了错误。 How i do i run the program in this case by defining the classpath too.在这种情况下,我如何通过定义类路径来运行程序。

It doesn't look like you're importing the package for RSyntaxTextArea.您似乎没有为 RSyntaxTextArea 导入 package。 Have you tried adding the following imports to your program?您是否尝试将以下导入添加到您的程序中?

import org.fife.ui.rtextarea.*;
import org.fife.ui.rsyntaxtextarea.*;

This code should do what you want... You needed to add the RSyntaxTextArea into the view (using the widget method)这段代码应该做你想做的......你需要将RSyntaxTextArea添加到视图中(使用widget方法)

You also needed to add it into a JScrollPane , so that it scrolls nicely when full.您还需要将它添加到JScrollPane中,以便它在满时很好地滚动。

import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL
import static javax.swing.JFrame.EXIT_ON_CLOSE
import org.fife.ui.rsyntaxtextarea.*

RSyntaxTextArea textArea = new RSyntaxTextArea()
textArea.syntaxEditingStyle = SyntaxConstants.SYNTAX_STYLE_JAVA

swing =  new SwingBuilder()
frame = swing.frame(title:"test", defaultCloseOperation:EXIT_ON_CLOSE, size:[600,400], show:true ) {
  borderLayout()
  panel( constraints:BL.CENTER ) {
    borderLayout()
    scrollPane( constraints:BL.CENTER ) {
      widget textArea
    }
  }
}

edit编辑

Without using widget, your code would need to look something like this:如果不使用小部件,您的代码将需要如下所示:

import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL
import static javax.swing.JFrame.EXIT_ON_CLOSE
import org.fife.ui.rsyntaxtextarea.*

RSyntaxTextArea textArea = new RSyntaxTextArea()
textArea.syntaxEditingStyle = SyntaxConstants.SYNTAX_STYLE_JAVA

swing =  new SwingBuilder()
frame = swing.frame(title:"test", defaultCloseOperation:EXIT_ON_CLOSE, size:[600,400], show:true ) {
  borderLayout()
  panel( constraints:BL.CENTER ) {
    borderLayout()
    sp = scrollPane( constraints:BL.CENTER )
    sp.viewport.add textArea
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM