Custom Create and Data Binding Questions

I'm learning IDEA so I've just created the GUI Designer chapter in the Intellij IDEA in Action book. The book seems out of date as it was written for IDEA 5 and I'm using the IDEA 6.0.2 GUI Designer. Therefore I'm confused about how a constructor would work with my simple ACME.form and its counterpart.

When I create the convertButton action listener it also makes a ACME constructor. At the same time I have selected to use the "Custom Create" property which creates the createUIComponents method.

When I try to run the ACME form I get the following error:

Exception in thread "main" java.lang.NullPointerException
at com.acme.conversion.currency.client.ACMEGUI.createUIComponents(
at com.acme.conversion.currency.client.ACMEGUI.$$$setupUI$$$(
at com.acme.conversion.currency.client.ACMEGUI.]]>(
at com.acme.conversion.currency.client.ACMEGUI.main(

This looks like a constructor related error but I'm not sure how to fix it. It would be helpful for me to learn through my ACME project how to correctly work with constructors. Another question, if I use the "Create Custom" option do I then have to initialize all or only some of the GUI components in the form?

Another question I have concerns Data Binding. I would like to load a forms components with data from a class that is not a JavaBean but does have its own get/set methods for the properties it maintains. The property system I want to bind to the GUI forms is part of the InfoNode Docking framework and its property classes which are not JavaBeans but kind of similar. Can I still accomplish this using the Data Binding Wizard or should I use a JavaBean as a go between class? InfoNodes property system is at

I've added the source for the file that has the constructor conflict and a basic data binding implementation below...

Best Regards,


package com.acme.conversion.currency.client;

import com.acme.conversion.currency.service.Currency;
import com.acme.conversion.currency.service.CurrencyExchangeService;
import com.acme.conversion.currency.service.CurrencyExchangeServiceFactory;

import javax.swing.*;
import java.util.Iterator;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.DecimalFormat;


  • Created by IntelliJ IDEA.

  • User: thomas

  • Date: Mar 6, 2007

  • Time: 4:47:02 PM

  • To change this template use File | Settings | File Templates.

public class ACMEGUI {
private JPanel mainPanel;
private JLabel amountToBeConvertedLabel;
private JLabel fromCurrencyLabel;
private JLabel toCurrencyLabel;
private JLabel resultLabel;
private JTextField amountToBeConvertedTextField;
private JComboBox fromCurrencyComboBox;
private JComboBox toCurrencyComboBox;
private JTextField resultTextField;
private JButton convertButton;
private JButton quitButton;

public ACMEGUI() {
convertButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
String fromCurrentString = (String)fromCurrencyComboBox.getSelectedItem();
String toCurrentString = (String)toCurrencyComboBox.getSelectedItem();
String amountString = amountToBeConvertedTextField.getText();

DecimalFormat df = new DecimalFormat("0.00");
try {
double amount = Double.parseDouble(amountString);
CurrencyExchangeService service = CurrencyExchangeServiceFactory.getService();
double rate = service.requestCurrentRate(fromCurrentString, toCurrentString);
resultTextField.setText(df.format(amount * rate));
} catch (NumberFormatException e) {
resultTextField.setText("The amount specified was not a valid number!");


private void createUIComponents() {
// TODO: place custom component creation code here

Iterator currencies = Currency.getCurrencies();
while (currencies.hasNext()) {
String currency = (String);


public static void main(String[] args) {
ACMEGUI acmiGui = new ACMEGUI();

final JFrame frame = new JFrame("ACME Currency Converter");

acmiGui.quitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {





public void setData(conversionBean data) {

public void getData(conversionBean data) {

public boolean isModified(conversionBean data) {
if (amountToBeConvertedTextField.getText() != null ? !amountToBeConvertedTextField.getText().equals(data.getAmountToBeConverted()) : data.getAmountToBeConverted() != null)
return true;
if (resultTextField.getText() != null ? !resultTextField.getText().equals(data.getResultText()) : data.getResultText() != null)
return true;
return false;

1 comment
Comment actions Permalink

Hi Thomas,

I think your problem is related to the order of method invocation: In your createUIComponents you assume that the buttons (fromCurrencyComboBox, toCurrencyComboBox) were already created. But this is not the case: createUIComponents is called before any of the ui-elements is instantiated.



Please sign in to leave a comment.