Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » Swing: using factory methods to build GUI
Swing: using factory methods to build GUI [message #607914] Fri, 10 June 2005 18:19
user is currently offline userFriend
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.
Previous Topic:No Visual Class option
Next Topic:Problem creating a new VE class
Goto Forum:
  


Current Time: Thu Apr 25 17:41:46 GMT 2024

Powered by FUDForum. Page generated in 0.03481 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top