Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » WindowBuilder Can not render GUI(WindowBuilder Designer does not show GUI if I call two or more than two level methods)
icon4.gif  WindowBuilder Can not render GUI [message #1011863] Wed, 20 February 2013 11:46 Go to next message
Sikandar Ali is currently offline Sikandar AliFriend
Messages: 3
Registered: February 2013
Junior Member
package com.swimap.omc.dcctool.view;

import java.awt.EventQueue;

public class MyFrame extends JFrame {

/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MyFrame frame = new MyFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public MyFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new GridBagLayout());

contentPane.add(getExpPathTf());

setContentPane(contentPane);
}

private JTextField getExpPathTf() {
JTextField exportPathTf = SwingUtil.createJTextField();
exportPathTf.setText("sikandar");
exportPathTf.setEditable(false);
return exportPathTf;
}

private static class SwingUtil {
public static JTextField createJTextField() {
JTextField tf = new JTextField();
tf.setBounds(10, 10, 100, 20);
return tf;
}
}

}
  • Attachment: MyFrame.java
    (Size: 1.39KB, Downloaded 95 times)
Re: WindowBuilder Can not render GUI [message #1012154 is a reply to message #1011863] Thu, 21 February 2013 01:23 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 886
Registered: July 2009
Location: Boston, MA
Senior Member
See the WindowBuilder docs on how to create and use Factory classes.

You will need to make the SwingUtil class a public top-level class (private/inner classes are not allowed) and mark the factory methods accordingly for WB to use them. Once I did that, your example rendered just fine.
icon4.gif  Re: WindowBuilder Can not render GUI [message #1012249 is a reply to message #1012154] Thu, 21 February 2013 07:36 Go to previous messageGo to next message
Sikandar Ali is currently offline Sikandar AliFriend
Messages: 3
Registered: February 2013
Junior Member
Thank you Eric Clayberg,
I feel that its not only a problem of Inner Private Class, please use these two files.
MyFrame1.java Razz
MyFrame2.java (Can't render UI) Sad

In the attached files there is a only one line difference
"System.out.println("abc");",

Please correct me If I amd doing something wrong. Sad
Re: WindowBuilder Can not render GUI [message #1012961 is a reply to message #1012249] Fri, 22 February 2013 14:22 Go to previous message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 886
Registered: July 2009
Location: Boston, MA
Senior Member
Your initial example was caused by using an inner/private class.

Your new example is something entirely different and also working as designed (for different reasons).

As written, your getTF() method does not represent a supported component creation pattern.

The method name begins with "get" which implies a getter, but it actually creates a new component every time rather than following the typical lazy creation pattern.

Even when it appears to "work", this is just a side effect of a different feature.

public JTextField getTF() {
  System.out.println("abc");
  return SwingUtil.createTF();
}

We have support for evaluating simple "single return statement" methods at design time to provide values for constants, parameters, etc. Once you add a second statement, we will no longer evaluate it given the likelihood of dangerous side effects at design time.

So...if you want to make it a real getter, follow the normal lazy creation patter like this:

private JTextField tf;
...
private JTextField getTF() {
  if (tf == null) {
    System.out.println("abc");
    tf = SwingUtil.createTF();
  }
  return tf;
}

And yes, extract SwingUtil into a top-level class, rename it to SomethingFactory, or mark the createTF() method as a factory...

class SwingUtil {
  /**
   * @wbp.factory
   */
  public static JTextField createTF() {
    JTextField tf = new JTextField();
    tf.setBounds(20, 20, 200, 20);
    tf.setText("Test : Text");
    return tf;
  }
}

Previous Topic:Java IDE and WindowBuilder
Next Topic:JTable data display
Goto Forum:
  


Current Time: Sat Dec 20 00:16:39 GMT 2014

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

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