I am writing a Griffon/Groovy/Swing application. However, I do like using WYSIWYG GUI tools like Eclipe's WindowBuilder tool as well.
I am wondering if it is possible to combine the two approaches? I'd like to use SwingBuilder
to manage view/model binding and some of the high level GUI tasks (like JDesktopPane
and JInternalFrame
), but have the contents designed into JFrame
s managed by WindowBuilder.
Here is a simple groovy script:
package example
import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL
count = 0
new SwingBuilder().edt {
frame(title: 'Frame', size: [300, 300], show: true) {
desktopPane() {
internalFrame(visible: true, bounds: [25, 25, 200, 100]) {
borderLayout()
textlabel = label(text: 'Click the button!', constraints: BL.NORTH)
button(text:'Click Me',
actionPerformed: {count++; textlabel.text = "Clicked ${count} time(s)."; println "clicked"}, constraints:BL.SOUTH)
}
internalFrame(visible: true, bounds: [50, 50, 200, 100]).add(new ExamplePanel())
}
}
}
and this is the ExamplePanel subclass of JFrame:
package example;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
public class ExamplePanel extends JPanel {
/**
* Create the panel.
*/
public ExamplePanel() {
setLayout(new BorderLayout(0, 0));
JLabel textLabel = new JLabel("Click the button!");
add(textLabel, BorderLayout.NORTH);
JButton button = new JButton("Click Me");
add(button, BorderLayout.SOUTH);
}
}
The groovy script creates a JDesktopPane
and two visually identical JInternalFrame
s. The second JInternalFrame
contains ExamplePanel
, but it has no infrastructure for detecting button clicks or altering the content of the label.
Is there a groovy way to get the same behaviour in the ExamplePanel
as I am getting in the SwingBuilder
defined internalFrame
?