サンプルコード
import java.awt.* import javax.swing.* import javax.swing.border.* import javax.swing.table.* import groovy.swing.* class MyHeader { def label def icon public MyHeader(label, icon) { this.label = label this.icon = icon } @Override public String toString() { return label } } class MyHeaderRenderer extends JLabel implements TableCellRenderer { public MyHeaderRenderer() { setBorder(BorderFactory.createRaisedBevelBorder()) } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setText(value.toString()) if( value instanceof MyHeader ){ setIcon(value.icon) } return this } } data = [ [category:'Database', product:'PostgreSQL'], [category:'Database', product:'MySQL'] ] sb = new SwingBuilder() sb.edt { frame( title: "example - labels and images for table headers", show: true, resizable: true, size: [300, 100], defaultCloseOperation: WindowConstants.EXIT_ON_CLOSE ){ scrollPane(){ table(id:"table"){ tableModel(list: data){ propertyColumn( header: new MyHeader("category", imageIcon(file:"e:/icons/home.png")), propertyName: "category", editable: false ) propertyColumn( header: new MyHeader("product", imageIcon(file:"e:/icons/plane.png")), propertyName: "product", editable: false ) } } table.tableHeader.setDefaultRenderer(new MyHeaderRenderer()) } } }実行時画面
動作環境
groovy 2.2.2, JDK 1.7 update55
0 件のコメント:
コメントを投稿