我试图将此类ScrollPaneDemo()
与我的SwingBuilder组合在一起,但是以任何方式单独存在都会出现这种情况,因为我可以将两个组合在一起,以作为我读过反射的同一接口出现,但我不知道该如何使用。
如何将此类添加JScrollPane
到我的挥杆生成器?
@Bindable
class Address {
String street, number, city
String toString() { "address[street=$street,number=$number,city=$city]" }
}
class ScrollPaneDemo extends JFrame {
ScrollPaneDemo() {
super("JScrollPane Demo");
ImageIcon ii = new ImageIcon("pokemon.png");
JScrollPane jsp = new JScrollPane(new JLabel(ii));
getContentPane().add(jsp);
setSize(300, 250);
setVisible(true);
jsp.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
System.out.println("Mouse X="+e.getY()+" Mouse Y="+e.getY());
}
});
}}
public static void main(String[] args) {
new ScrollPaneDemo();
}
更多定义
def address = new Address(street: 'Evergreen Terrace', number: '742', city: 'Springfield')
def swingBuilder = new SwingBuilder()
swingBuilder.edt { // edt method makes sure UI is build on Event Dispatch Thread.
lookAndFeel 'nimbus' // Simple change in look and feel.
frame(title: 'Address', size: [1000, 800],
show: true, locationRelativeTo: null,
defaultCloseOperation: EXIT_ON_CLOSE) {
borderLayout(vgap: 5)
panel(constraints: BorderLayout.CENTER,
border: compoundBorder([emptyBorder(10), titledBorder('Enter your address:')])) {
tableLayout {
tr {
td {
label 'Street:' // text property is default, so it is implicit.
}
td {
textField address.street, id: 'streetField', columns: 20
}
}
tr {
td {
label 'Number:'
}
td {
textField id: 'numberField', columns: 5, text: address.number
}
}
tr {
td {
label 'City:'
}
td {
textField id: 'cityField', columns: 20, address.city
}
td {
textField id: 'cityField', columns: 20, address.city
}
}
}
new ScrollPaneDemo();
}
panel(constraints: BorderLayout.SOUTH) {
button text: 'Save', actionPerformed: {
println address
}
}
// Binding of textfield's to address object.
bean address,
street: bind { streetField.text },
number: bind { numberField.text },
city: bind { cityField.text }
}
}
我用这段代码解决
scrollPane(id:'scroll',preferredSize: [200,200], constraints: context.CENTER) {
panel(layout: new FlowLayout()) {
label(icon: imageIcon(new URL('file:///path/pokemon.png')))
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句