custom widgets don't show

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

custom widgets don't show

Postby Hans » Sun Sep 04, 2005 3:01 pm

We have a panel that contains both standard widgets and some custom widgets that are created through a separate factory. In the designer only the standard widgets are shown. When I create a test class in the same project that creates the panel throug a no-arg constructor all widgets are displayed.
Could this still be a classpath issue? What is the best way to debug this in designer and find out why the widgets are not displayed when the panel instance is created from designer?

Hans Boerstra
Hans
 

Re: custom widgets don't show

Postby Eric Clayberg » Sun Sep 04, 2005 3:25 pm

Hans wrote:We have a panel that contains both standard widgets and some custom widgets that are created through a separate factory. In the designer only the standard widgets are shown. When I create a test class in the same project that creates the panel throug a no-arg constructor all widgets are displayed. Could this still be a classpath issue? What is the best way to debug this in designer and find out why the widgets are not displayed when the panel instance is created from designer?

The Designer parser is not going to understand an arbitrary factory creation method, so those widgets would be ignored.

Try instantiating your widgets with the normal zero argument constructor and see if it helps.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: custom widgets don't show

Postby Guest » Sun Sep 04, 2005 10:05 pm

Eric Clayberg wrote:
Hans wrote:We have a panel that contains both standard widgets and some custom widgets that are created through a separate factory. In the designer only the standard widgets are shown. When I create a test class in the same project that creates the panel throug a no-arg constructor all widgets are displayed. Could this still be a classpath issue? What is the best way to debug this in designer and find out why the widgets are not displayed when the panel instance is created from designer?

The Designer parser is not going to understand an arbitrary factory creation method, so those widgets would be ignored.

Try instantiating your widgets with the normal zero argument constructor and see if it helps.

That's my problem: these widgets can not be instantiated like that. I used a seperate method to create widgets and assign them to fields and then in another method add them to the parent JPanel using the field references. Could that work or would Designer need to understand the widget creation too and the assigned widget fields are not enough?

Hans Boerstra
Guest
 

Postby Hans » Mon Sep 05, 2005 6:25 am

After reading the documentation (ok, ok: RTFM ;-), I understand what the problem is of calling an arbitrary factory method because this has to be recreated in a target JVM without being able to execute the actual given statements.
I would think that this (using factory instances) is a general issue though: it is quite common to create a factory instance, set properties on it and then call its create methods. JGoodies builders like DefaultFormBuilder do the same for working with dynamic FormLayouts.
Is there a workaround solution to keep the easy of use for manual coding with factories/builders and still use Designer for the WYSIWYG layout stuff?

Hans Boerstra
Hans
 

Postby Eric Clayberg » Tue Sep 06, 2005 5:50 pm

The latest v4.1.1 build can now understand most widget creation factory methods.

Give it a try, and, if it does not work in your case, send us a small, self-contained test case.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby Hans » Thu Sep 08, 2005 10:01 am

Eric Clayberg wrote:The latest v4.1.1 build can now understand most widget creation factory methods.

Give it a try, and, if it does not work in your case, send us a small, self-contained test case.

It is better, but still not complete. Below the test class. I sent the two other files through e-mail because I could figure out how to attach files on the forum.

Regards,

Hans

Code: Select all
package nl.test.eclipse.swing;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class TestFactory2 extends JFrame {

   static final long serialVersionUID = 12345;
   
   private JPanel jContentPane = null;
   
   private Factory factory = null;

   /**
   * This is the default constructor
   */
   public TestFactory2() {
   super();
   initialize();
   }

   /**
   * This method initializes this
   *
   * @return void
   */
   private void initialize() {
      Factory.initialize("nl.test.eclipse.swing.");
      factory = new Factory("assigned value", String.class);
      this.setSize(300, 200);
      this.setContentPane(createContent());
      this.setTitle("JFrame");
   }

   /**
   * This method initializes jContentPane
   *
   * @return javax.swing.JPanel
   */
   private JPanel createContent() {
      if (jContentPane == null) {
         jContentPane = new JPanel();
         jContentPane.setLayout(new BorderLayout());
         JTextField ctrl = factory.getTextField("text");
         JLabel lbl = new JLabel();
         lbl.setText(factory.getLabelText("name"));
         jContentPane.add(lbl, BorderLayout.NORTH);
         jContentPane.add(ctrl, BorderLayout.SOUTH);
      }
      return jContentPane;
   }
}
Hans
 


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest