2

我是 groovy 和 griffon 的新手,目前正在玩一些 SwingBuilder。我想添加一个 JSplitPane 的子类(它使用http://www.formdev.com/blog/swing-tip-jsplitpane-with-zero-size-divider/中描述的细分隔线)。

您可以在下面找到视图定义脚本。我使用了一个 container()-Element 来添加我的 Splitpane 子类。当我启动我的应用程序时,我得到一个 java.lang.IllegalArgumentException。任何想法如何解决这一问题?


风景:

frame(id:"frame",
 title: 'The new database explorer implemented with groovy/griffon',
 size: [600, 400],
 locationByPlatform:true,
 iconImage: imageIcon('/griffon-icon-48x48.png').image,
 iconImages: [imageIcon('/griffon-icon-48x48.png').image,
              imageIcon('/griffon-icon-32x32.png').image,
              imageIcon('/griffon-icon-16x16.png').image]) {

   panel (id:'mainPanel',
           opaque:false) {
       borderLayout()
       toolBar(id:'toolBar',
               constraints:NORTH,
               floatable:false,
               opaque: false,
               preferredSize: new Dimension(200,50)) {
           hglue()
           textField(id:'search', "clientPropertyJTextField.variant":"search",
                   maximumSize: new Dimension(150,35),
                   preferredSize: new Dimension(150,35))
       }
       panel(id: 'centerPanel',
               constraints: CENTER,
               opaque: true,
               background: new Color(238, 238, 238)) {
           borderLayout()
           container (new SplitPaneWithThinDivider(),
                      id:'mainSplitPane',
                      constraints: CENTER,
                      dividerLocation: 150
                      ) {
               scrollPane(id:'treeScroller', border:null) {
                   tree(id:'explorerTree',
                           rootVisible: false)
               }
               scrollPane(border:null) {
                   textArea()
               }
           }
       }
   }
}

例外:

2012-03-15 06:45:01,778 [AWT-EventQueue-0] 错误 org.codehaus.griffon.runtime.builder.UberBuilder - 构建 at.rehdie.dbexp.main.ExplorerFrameView@59c87031 时出错
java.lang.IllegalArgumentException:无法添加到布局:未知约束:null
    在 java_awt_Container$add.call(未知来源)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:140)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4_closure7_closure8.doCall(ExplorerFrameView.groovy:54)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4_closure7_closure8.doCall(ExplorerFrameView.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:140)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4_closure7.doCall(ExplorerFrameView.groovy:49)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4_closure7.doCall(ExplorerFrameView.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:140)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4.doCall(ExplorerFrameView.groovy:47)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4.doCall(ExplorerFrameView.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:140)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2.doCall(ExplorerFrameView.groovy:31)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2.doCall(ExplorerFrameView.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:167)
    在 at.rehdie.dbexp.main.ExplorerFrameView.run(ExplorerFrameView.groovy:23)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:151)
    在 org.codehaus.griffon.runtime.builder.UberBuilder.build(UberBuilder.groovy:155)
    在 org.codehaus.griffon.runtime.core.AbstractMVCGroup$1.run(AbstractMVCGroup.java:129)
2012-03-15 06:45:01,781 [main] 错误 griffon.util.GriffonExceptionHandler - 未捕获的异常
java.lang.RuntimeException:java.lang.IllegalArgumentException:无法添加到布局:未知约束:null
    在 griffon.swing.SwingUIThreadHandler.executeSync(SwingUIThreadHandler.java:46)
    在 griffon.core.UIThreadManager.executeSync(UIThreadManager.java:247)
    在 org.codehaus.griffon.runtime.core.AbstractMVCGroup.buildScriptMember(AbstractMVCGroup.java:127)
    在 org.codehaus.griffon.runtime.core.DefaultMVCGroupManager.initializeMembers(DefaultMVCGroupManager.java:230)
    在 org.codehaus.griffon.runtime.core.DefaultMVCGroupManager.buildMVCGroup(DefaultMVCGroupManager.java:149)
    在 org.codehaus.griffon.runtime.core.AbstractMVCGroupManager.createMVCGroup(AbstractMVCGroupManager.java:238)
    在 org.codehaus.griffon.runtime.core.AbstractMVCGroupManager.createMVCGroup(AbstractMVCGroupManager.java:186)
    在 org.codehaus.griffon.runtime.core.AbstractGriffonApplication.createMVCGroup(AbstractGriffonApplication.java:499)
    在 org.codehaus.griffon.runtime.core.AbstractGriffonApplication.startup(AbstractGriffonApplication.java:313)
    在 griffon.swing.AbstractSwingGriffonApplication.realize(AbstractSwingGriffonApplication.java:78)
    在 griffon.swing.AbstractSwingGriffonApplication.run(AbstractSwingGriffonApplication.java:132)
    在 griffon.swing.SwingApplication.main(SwingApplication.java:36)
引起:java.lang.IllegalArgumentException:无法添加到布局:未知约束:null
    在 java_awt_Container$add.call(未知来源)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:140)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4_closure7_closure8.doCall(ExplorerFrameView.groovy:54)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4_closure7_closure8.doCall(ExplorerFrameView.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:140)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4_closure7.doCall(ExplorerFrameView.groovy:49)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4_closure7.doCall(ExplorerFrameView.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:140)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4.doCall(ExplorerFrameView.groovy:47)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2_closure4.doCall(ExplorerFrameView.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:140)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2.doCall(ExplorerFrameView.groovy:31)
    在 at.rehdie.dbexp.main.ExplorerFrameView$_run_closure2.doCall(ExplorerFrameView.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeFactoryMethod(UberInterceptorMetaClass.groovy:96)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.this$3$invokeFactoryMethod(UberInterceptorMetaClass.groovy)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass$this$3$invokeFactoryMethod.callCurrent(Unknown Source)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:167)
    在 at.rehdie.dbexp.main.ExplorerFrameView.run(ExplorerFrameView.groovy:23)
    在 org.codehaus.griffon.runtime.builder.UberInterceptorMetaClass.invokeMethod(UberInterceptorMetaClass.groovy:151)
    在 org.codehaus.griffon.runtime.builder.UberBuilder.build(UberBuilder.groovy:155)
    在 org.codehaus.griffon.runtime.core.AbstractMVCGroup$1.run(AbstractMVCGroup.java:129)
4

3 回答 3

2

一个疯狂的、未经检验的猜测,但确实:

       widget( new SplitPaneWithThinDivider(),
               id:'mainSplitPane',
               constraints: CENTER,
               dividerLocation: 150,
               leftComponent: scrollPane(id:'treeScroller', border:null) {
                 tree(id:'explorerTree', rootVisible: false )
               },
               rightComponent: scrollPane(border:null) {
                 textArea()
               } )

工作吗?

于 2012-03-16T12:45:01.197 回答
0

感谢您的回复,蒂姆的版本完美运行。我还尝试了以下方法:

splitPane (new SplitPaneWithThinDivider(),
           id:'mainSplitPane',
           constraints: CENTER,
           dividerLocation: 150,
           "clientPropertyQuaqua.Tree.style": "sideBar",
           border: null) {

   scrollPane(id:'treeScroller', border:null) {
       tree(id:'explorerTree',
            rootVisible: false)
   },           
   scrollPane(border:null) {
       textArea()
   }           
}

但是这样,拆分窗格的左侧组件始终是默认的“左按钮”(当我使用new JSplitPane()而不是时也是如此new SplitPaneWithThinDivider())。

当我将其更改为

splitPane (new SplitPaneWithThinDivider(),
           id:'mainSplitPane',
           constraints: CENTER,
           dividerLocation: 150,
           "clientPropertyQuaqua.Tree.style": "sideBar",
           border: null) {

   scrollPane(id:'treeScroller', border:null) {
       tree(id:'explorerTree',
            rootVisible: false)
   },           
   scrollPane(border:null) {
       textArea()
   }           
}
bean(mainSplitPane, leftComponent: treeScroller)

有效。

于 2012-03-17T07:05:10.997 回答
0

使用 Griffon 0.9.5-rc2 尝试了代码,但使用了 application() 而不是 frame() 和 splitPane(),因为我无法访问自定义的 SplitPaneWithThinDivider 组件并且它可以工作。我认为 ExplorerFrameView 属于辅助 MVC 组。您是否尝试过使用 application() 而不是 frame() ?

每个视图可以有尽可能多的 application() 节点,因为该节点具有与 frame() 几乎相同的行为,但它知道如何处理小程序。

于 2012-03-16T13:14:07.413 回答