Netbeans: JPanel in designer mode with code behind.

I wanted to add a JPanel to my palette so I could easily include it into a JFrame, in designer mode that is.

This was the constructor of my JPanel:

/** Creates new form SetupPanel */
public SetupPanel()
{
	super();
	this.initComponents();

	this.jTextFieldDataDirectory.setText(Main.getProperties().getProperty(Settings.DATADIRECTORY));
	this.jTextFieldOpenSSLLocation.setText(Main.getProperties().getProperty(Settings.OPENSSLLOCATION));
}

This gave me a nice error when I added it to the panel:

The component cannot be instantiated. Please make sure it is a JavaBeans component.

This is because when you add it to the palette Netbeans compiles the class, and at that point it cannot find ‘Main’, so it throws a NullPointer.

Surrounding those statements with Beans.isDesignTime() solves the problem:

/** Creates new form SetupPanel */
public SetupPanel()
{
	super();
	this.initComponents();

	if (!Beans.isDesignTime())
	{
		this.jTextFieldDataDirectory.setText(Main.getProperties().getProperty(Settings.DATADIRECTORY));
		this.jTextFieldOpenSSLLocation.setText(Main.getProperties().getProperty(Settings.OPENSSLLOCATION));
	}
}

Now you can add it to the palette without problems.

.NET: Entity Framework: re-add a deleted table resolved!

First of all: for those who think that there is an easy solution. I’m sorry, there is not.

The problem is located in the .edmx file, and not in the designer.cs file as I suspected first.

When you add an .edmx and take a look at it with notepad you’ll see this:



	
	
		
		
			
				
				
			
		
		
		
			
				
				
			
		
		
		
			
				
				
			
		
	
	
	
		
			
				
			
		
		
			
				
			
		
		
		
			
			
		
	

Now you add a table:



	
	
		
		
			
				
					
				
				
					
						
					
					
					
					
				
			
		
		
		
			
				
					
				
				
					
						
					
					
					
					
				
			
		
		
		
			
				
					
						
							
								
								
								
							
						
					
				
			
		
	
	
	
		
			
				
			
		
		
			
				
			
		
		
		
			
				
			
		
	

As you can see I’ve added a table ‘Users’ with ‘UserID’, ‘Name’ and ‘Birthday’.

You can also see the difference between the 2.

Now when you delete the table again from the design surface this is what ‘junk’ that stays behind:



	
	
		
		
			
				
					
				
				
					
						
					
					
					
					
				
			
		
		
		
			
				
				
			
		
		
		
			
				
				
			
		
	
	
	
		
			
				
			
		
		
			
				
			
		
		
		
			
			
		
	

As you can see lines 9 and 12-17 weren’t there in the original -empty- model. You’ll need to clean those up manually.

diff

Removing those lines will give you the possibility to re-add your previously deleted table.