SwingBuilder中使用Jtable,例3

import java.awt.*
import javax.swing.*
import javax.swing.table.*
import groovy.swing.SwingBuilder

class MyTableCellRenderer extends JLabel
implements TableCellRenderer {
    public Component getTableCellRendererComponent(
                        JTable table, Object value,
                        boolean isSelected, boolean hasFocus,
                        int rowIndex, int vColIndex) {
        
        setText(value.toString())

        File file = new File(value)

        if( !file.exists() ) { setForeground(Color.red) }

        return this
    }
}

///////////////////////////////////////////////////////////////
// static public void main(String[] args)
//
// args[0] = env var to view

final String DELIMITER = ';'   // change this for Unix

String envVar = System.getenv(args[0])

// Build data

String[] columns = [ args[0] ]

String[] values = envVar.split(DELIMITER)
Object[][] data = new String[values.length]

for( i in 0..values.length-1 ) {
    String[] row = new String[1]
    row[0] = values[i]
    data[i] = row
}

// Build GUI. Note that this is quick-n-dirty stuff,
// that illustrates a SwingBuilder more than proper
// Swing techniques.

builder = new SwingBuilder()

JTable table = new JTable(data, columns)
def renderer = new MyTableCellRenderer()
table.columnModel.getColumn(0).setCellRenderer(renderer)
JScrollPane scrollPane = new JScrollPane(table)

gui = builder.frame( title:'Code to Joy',
                 size:[520,500] ) {
    panel( layout: new BorderLayout(),
           constraints: BorderLayout.NORTH ) {
       widget(scrollPane)   // THIS is a revelation
   }
}

gui.show()

http://codetojoy.blogspot.com/2007/08/groovy-swingbuilder-and-secret-methods.html

你可能感兴趣的:(html,swing,unix,groovy)