GUI Builder: unable to access components via bound class
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.
Please sign in to leave a comment.
Please share a sample project to reproduce the problem.
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?
Create a new dummy project with the relevant code that illustrates the problem and share it. We don't need your real project.
How do I get it to you?
Share via Dropbox, Google Drive, or create a support ticket with attach, or upload per https://intellij-support.jetbrains.com/hc/en-us/articles/206869619-Uploading-Large-Files-for-JetBrains-Support-Team.
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.
You can see the generated code if you enable this option:
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.
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!