表使用groovy的摇摆建设者

时间:2010-12-29 11:56:52

标签: groovy html-table swingbuilder

到目前为止,我已经开发了PHP和JavaScript。我目前正在学习groovy,但不幸的是,关于这门语言和书的教程并不多,我现在正在阅读(Groovy Recipes),并没有关于使用groovy的swingbuilder的任何内容。

作为一个正在进行的项目,我想创建一个类似于下面的模式的表:

                                      Instancename 

groupId      artifactId               DEV     TEST   PROD            

firstgroup   firstartifact            1.00    1.05   1.05
secondgroup  secondartifact           2.02    2.00   2.00

这是我目前的代码:

import groovy.swing.SwingBuilder
import java.awt.BorderLayout

public class Gui {

 public void createGui(String instanceTitle, ArrayList<Artifact> columnData){

  def bldr = new groovy.swing.SwingBuilder();

  def frame = bldr.frame(
   title: "Overview",
   size: [600,150],
   defaultCloseOperation:javax.swing.WindowConstants.EXIT_ON_CLOSE
  ){  
   def tab = table(constraints:BorderLayout.CENTER) {
    tableModel(list:columnData) {
     propertyColumn(header:'GroupId', propertyName:'groupId')
     propertyColumn(header:'ArtifactId', propertyName:'artifactId')
     propertyColumn(header:'Dev', propertyName:'devVersion')
     propertyColumn(header:'Test', propertyName:'testVersion')
     propertyColumn(header:'Prod', propertyName:'prodVersion')
    }
   }
   widget(constraints:BorderLayout.NORTH, tab.tableHeader)
  }
  frame.pack()
  frame.show();

  }

}

当我运行这个时,我得到的表填满了我的数据。我的问题是,如何将“DEV”,“TEST”和“PROD”从属于“Instancename”?我不知道如何在其他人之上添加标题。 在HTML中,它看起来像这样:

<table>
 <tr>
  <td colspan="2"></td>
  <td colspan="3">Instancename</td>
 </tr>
 <tr>
  <td>groupId</td>
  <td>artifactId</td>
  <td>DEV</td>
  <td>TEST</td>
  <td>PROD</td>
 </tr>
 <tr>
  <td>firstgroupid</td>
  <td>firstartifactid</td>
  <td>firstdevversion</td>
  <td>firsttestversion</td>
  <td>firstprodversion</td>
 </tr>
 ...
</table>

PS:如果你知道一些很好的常规教程,请告诉我:)。

1 个答案:

答案 0 :(得分:1)

我认为这更像是一个Swing问题,而不是一个常规的摇摆建设者。

没有简单的方式来定义表头,就像在HTML中一样。

Here's an example of how you'd do this in Java with Swing,但它已经11岁了,我不相信Java 1.5 + ...

确实有一个old fix on the (now kaput) sun java forums about how to get this code running under Java 1.5+

这实际上并不是我曾经记得的UI模式(即使在HTML中也很容易),所以也许以不同的方式显示您的数据会更好(或至少对最终用户更容易识别)?