Skip to main content



      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 05:38 Go to next message
Eclipse UserFriend
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 12:48 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Error when using addComponentListener in a getter [message #777587 is a reply to message #777361] Tue, 10 January 2012 14:08 Go to previous messageGo to next message
Eclipse UserFriend
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 03:56 Go to previous message
Eclipse UserFriend
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: Mon Jul 07 09:07:43 EDT 2025

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

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

Back to the top