Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Error when using addComponentListener in a getter
Error when using addComponentListener in a getter [message #777361] Tue, 10 January 2012 10:38 Go to next message
Rayleigh Missing name is currently offline Rayleigh Missing nameFriend
Messages: 20
Registered: July 2011
Junior Member
The following example shows a blank screen in Window Builder:

import javax.swing.JFrame;


public class Frame extends JFrame{
	
	private JPanel panel;
	
	public Frame(){
		super();
		initialize();
	}
	
	private void initialize() {
		this.setName("ABC");
		this.setLocation(0, 10);
		this.setSize(990, 750);
		this.setTitle("abc");
		this.setContentPane(this.getPanel());
	}
	
	protected JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			
			JLabel lblTest = new JLabel("lala");
			panel.add(lblTest);
			
		}
		panel.addComponentListener(new java.awt.event.ComponentAdapter() {
			public void componentResized(java.awt.event.ComponentEvent e) {
				// abc
			}
		});
		
		return panel;
	}
}


But if panel.addComponentListener is moved into the if block, it works
protected JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			
			JLabel lblTest = new JLabel("lala");
			panel.add(lblTest);
			
			panel.addComponentListener(new java.awt.event.ComponentAdapter() {
				public void componentResized(java.awt.event.ComponentEvent e) {
					// abc
				}
			});
		}
		
		return panel;
	}


Is it possible to get it working without touching the code? We've got a lot of legacy code that isn't even ours and we can't check and update a thousand panels.
Re: Error when using addComponentListener in a getter [message #777561 is a reply to message #777361] Tue, 10 January 2012 17:48 Go to previous messageGo to next message
Konstantin Scheglov is currently offline Konstantin ScheglovFriend
Messages: 555
Registered: July 2009
Senior Member
Rayleigh Mising name wrote on Tue, 10 January 2012 05:38

Is it possible to get it working without touching the code? We've got a lot of legacy code that isn't even ours and we can't check and update a thousand panels.


In theory - yes.
Practically this is violation of lazy pattern and I don't want to include this into WindowBuilder codebase.

If you want, you could make your custom version with tweaked
org.eclipse.wb.internal.core.model.variable.LazyVariableSupportUtils.getInformation(MethodDeclaration)
method.


Konstantin Scheglov,
Google, Inc.
Re: Error when using addComponentListener in a getter [message #777587 is a reply to message #777361] Tue, 10 January 2012 19:08 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
Rayleigh Mising name wrote on Tue, 10 January 2012 05:38
Is it possible to get it working without touching the code? We've got a lot of legacy code that isn't even ours and we can't check and update a thousand panels.

You really should fix this code. As written, having panel.addComponentListener outside of the if block is very bad and will lead to the same listener being added multiple times (a serious bug). This is not something we want to encourage or support. If you are going to use the lazy pattern, use it correctly.
Re: Error when using addComponentListener in a getter [message #779651 is a reply to message #777361] Mon, 16 January 2012 08:56 Go to previous message
Rayleigh Missing name is currently offline Rayleigh Missing nameFriend
Messages: 20
Registered: July 2011
Junior Member
Ok, I'll try to find all occurrences of this bug and fix them. Thanks.
Previous Topic:Odd Display of WindowBuilder (Ubuntu 11.10, Eclipse 4.2, Compiz)
Next Topic:Create a new plug-in that contributes to WindowBuilder
Goto Forum:
  


Current Time: Thu Apr 25 22:30:23 GMT 2024

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

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

Back to the top