GUI Builder: unable to access components via bound class

Answered

I have a Swing form with a bound Java class created in the GUI builder.

The form and its listeners are running fine. It's initialised from a class outside the form:

form = new TradeManagerForm();
form.setStrategy(this);

JFrame panel = new JFrame("Trade Manager");
panel.setContentPane(form.getMainPanel());
panel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.pack();
panel.setVisible(true);

The builder has added all the form components as class properties in the bound class. According to the docs, I should be able to add runtime functionality to the form via these class properties:

https://www.jetbrains.com/help/idea/2016.1/bound-class.html

I've set up accessors within the bound class so the app can interact with the form (eg, enable/disable buttons), but none of them work. When called, nothing changes on the form and no error is thrown. Here's an example accessor:

public void testForm(){

labelFoo.setText("Test value!");
labelFoo.setForeground(Color.RED);
buttonFoo.setEnabled(false);
}

I've tried calling repaint() on the component after each change but it hasn't helped. It shouldn't be required anyway, as I understand it.

I'm a Swing and IDEA newbie, so am probably doing something dim. Please help - this is a show-stopper for my project.

 

9 comments
Comment actions Permalink

Please share a sample project to reproduce the problem.

0
Comment actions Permalink

Hi Serge - it's a large project (dozens of classes) with proprietary code. But I've provided everything that seems to be relevant. What more do you need?

0
Comment actions Permalink

Create a new dummy project with the relevant code that illustrates the problem and share it. We don't need your real project.

0
Comment actions Permalink

How do I get it to you?

0
Comment actions Permalink

Hi Serge

I've created a dummy project, but unfortunately it works!

How can I troubleshoot my broken form? I understand why  you're using the XML approach but the problem is that everything is behind-the-scenes magic and I can't see the generated code. 

 

0
Comment actions Permalink

You can see the generated code if you enable this option:

0
Comment actions Permalink

OK - I've found my issue - my bad - I was doing something stupid.

Sorry for wasting your time. Thanks for the quick response - much appreciated.

0
Comment actions Permalink

Thanks for showing me the GUI designer option - very useful. IDEA is amazingly flexible and powerful, but it can sometimes be a struggle to find the features!

0

Please sign in to leave a comment.