bbrodt / jsyntaxpane

Automatically exported from code.google.com/p/jsyntaxpane
0 stars 1 forks source link

Doesn't play nice with Groovy's SwingBuilder #178

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Use Groovy's SwingBuilder API to try creating an editorPane with content type 
'text/groovy'
2.
3.

What is the expected output? What do you see instead?
I would expect a working editor pane. Instead it throws an exception stating 
"Sep 9, 2011 4:42:00 PM jsyntaxpane.components.LineNumbersRuler install
WARNING: JEditorPane is not enclosed in JScrollPane, no LineNumbers will be 
displayed
Caught: java.lang.NullPointerException"

What version of the product are you using? On what operating system?
0.9.5-b29 on Win XP SP3

Please provide any additional information below.
Example script:

import groovy.swing.SwingBuilder
import java.awt.Component
import javax.swing.BoxLayout
import javax.swing.border.EmptyBorder

def swing = new SwingBuilder()

jsyntaxpane.DefaultSyntaxKit.initKit();

swing.edt{
    frame( title:'Test', pack:true, show:true ){
        panel(){
            scrollPane( preferredSize:[1000, 400], maximumSize:[1000, 450] ){
                editorPane( contentType: ("text/groovy"), text:"println \"Hello\"")
            }
        }
    }
}

Original issue reported on code.google.com by FGregu...@gmail.com on 9 Sep 2011 at 9:45

GoogleCodeExporter commented 8 years ago
Sorry, had a few unused imports in there... here it is again:

import groovy.swing.SwingBuilder

def swing = new SwingBuilder()

jsyntaxpane.DefaultSyntaxKit.initKit();

swing.edt{
    frame( title:'Test', pack:true, show:true ){
        panel(){
            scrollPane( preferredSize:[1000, 400], maximumSize:[1000, 450] ){
                editorPane( contentType: ("text/groovy"), text:"println \"Hello\"")
            }
        }
    }
}

Original comment by FGregu...@gmail.com on 9 Sep 2011 at 9:46

GoogleCodeExporter commented 8 years ago
Found a workaround. It looks like it just doesn't like Groovy's dynamic 
constructors. For example, this does not work:

import java.awt.Dimension
import javax.swing.JEditorPane
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.JScrollPane

jsyntaxpane.DefaultSyntaxKit.initKit();

def frame = new JFrame()
frame.title = "Test"

def panel = new JPanel()
def editor = new JEditorPane(contentType:"text/groovy")
def scPane = new JScrollPane(editor)

panel.add(scPane)
frame.add(panel)

scPane.setPreferredSize(new Dimension(1000,400))
frame.pack()
frame.show()

But this does work:

import java.awt.Dimension
import javax.swing.JEditorPane
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.JScrollPane

jsyntaxpane.DefaultSyntaxKit.initKit();

def frame = new JFrame()
frame.title = "Test"

def panel = new JPanel()
def editor = new JEditorPane()
def scPane = new JScrollPane(editor)
editor.setContentType("text/groovy")

panel.add(scPane)
frame.add(panel)

scPane.setPreferredSize(new Dimension(1000,400))
frame.pack()
frame.show()

So to go back to my example, the workaround would look something like this:

import groovy.swing.SwingBuilder

def swing = new SwingBuilder()

jsyntaxpane.DefaultSyntaxKit.initKit();

swing.edt{
    frame( title:'Test', pack:true, show:true ){
        panel(){
            scrollPane( preferredSize:[1000, 400], maximumSize:[1000, 450] ){
                editorPane( id:'ePane', text:"println \"Hello\"")
                swing.ePane.setContentType('text/groovy')
            }
        }
    }
}

Original comment by FGregu...@gmail.com on 9 Sep 2011 at 10:20