サンプルコード
import java.awt.* import javax.swing.* import groovy.swing.* data = [ [category:'City', city:'Tokyo'], [category:'City', city:'Osaka'], [category:'City', city:'Sapporo'] ] sb = new SwingBuilder() def popupMenu = sb.popupMenu() { menuItem() { action( name:'Information', closure:{ if( sb.table.getSelectedRowCount() != 0 ){ sb.optionPane( message:(sb.table.getSelectedRows() as ArrayList<Integer>) .collect {sb.table.model.getValueAt(it,1)}.join(","), messageType:JOptionPane.INFORMATION_MESSAGE) .createDialog("table").visible = true } else { sb.optionPane( message:"no row selected", messageType:JOptionPane.INFORMATION_MESSAGE) .createDialog("table").visible = true } } ) } } sb.edt { frame( title: "example - table with popup menu", show: true, resizable: true, size: [300, 100], defaultCloseOperation: WindowConstants.EXIT_ON_CLOSE ){ scrollPane(){ table(id:"table", componentPopupMenu:popupMenu){ tableModel(list: data){ propertyColumn( header:"category", propertyName: "category", editable: false ) propertyColumn( header:"city", propertyName: "city", editable: false ) } } } } }実行時画面
動作環境
groovy 2.2.2, JDK 1.7 update55
0 件のコメント:
コメントを投稿