Swing: using factory methods to build GUI [message #607914] |
Fri, 10 June 2005 18:19 |
user Messages: 296 Registered: July 2009 |
Senior Member |
|
|
Hello,
Using VE version 1.0.1.1 (the latest stable), I tried building a JPanel
subclass with many JButtons. I want all of the buttons have the same
properties - except for the text - so I thought of this approach:
// class MyPanel extends JPanel
private JButton getRedButton(String text) {
JButton button=new JButton(text);
button.setBackground(java.awt.Color.red);
button.set...(..);
return button;
}
Then, every button's getter method looks like this:
private JButton getFirst() {
if (first==null) {
first=getRedButton("First");
first.setSomeUniqueProperty(...);
}
return first;
}
Of-course, MyPanel.initialize() adds get*() to the panel.
This approach works, but... The Visual Editor doesn't show these buttons
on the panel. It doesn't even show them in the Java Beans tree. This
behavior makes it very hard to design complex UIs. In fact, it also
makes the VE useless for this case.
What am I doing wrong? I know, I can do everything in the "regular" way
- set all properties in the getters. But that means a lot of code
duplication.
Please suggest ways to fix the problem.
Thanks,
Noam.
|
|
|
Powered by
FUDForum. Page generated in 0.03481 seconds