开发者

Table using groovy's swing builder

开发者 https://www.devze.com 2023-02-01 08:59 出处:网络
Until now I\'ve developed in PHP and JavaScript. I\'m currently learning groovy, but unfortunately there aren\'t many tutorials about this language and the book, I\'m currently reading (Groovy Recipes

Until now I've developed in PHP and JavaScript. I'm currently learning groovy, but unfortunately there aren't many tutorials about this language and the book, I'm currently reading (Groovy Recipes), doesn't contain anything about using groovy's swingbuilder.

As a project at work, I'd like to create a table like the schema bellow:

                                      Instancename 

groupId      artifactId               DEV     TEST   PROD            

firstgroup   firstartifact            1.00    1.05   1.05
secondgroup  secondartifact           2.02    2.00   2.00

That's my current code:

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();

  }

}

When I run this, I get the table filled with my data. My question is, how can I subordinate "DEV", "TEST" and "PROD" to "Instancename"? I don't know how to add a header above the others. In html it would look like this:

<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: If you know some good groovy tutorials, let me know :)


I think this is more of a Swing question rather than a groovy swingbuilder one.

There is no simple way to define table headers as you would in HTML.

Here's an example of how you'd do this in Java with Swing, but it's 11 years old and I don't believe works with Java 1.5+...

Indeed there's an old fix on the (now kaput) sun java forums about how to get this code running under Java 1.5+

This isn't really a UI pattern that I ever remember seeing however (even in HTML where it's easy) so maybe a different way of showing your data would be better (or at least more recognisable to end users)?

0

精彩评论

暂无评论...
验证码 换一张
取 消