<p>I'm trying to get into java again (it's been a few years). I never really did any GUI coding in java. I've been using Netbeans to get started with this.</p>

<p>When using winforms in C# at work I use a usercontrols to build parts of my UI and add them to forms dynamically. </p>

<p>I've been trying to use <code>JPanels</code> like usercontrols in C#. I created a <code>JPanel</code> form called <code>BlurbEditor</code>. This has a few simple controls on it. I am trying to add it to another panel at run time on a button event. </p>

<p>Here is the code that I thought would work:</p>

<pre><code>mainPanel.add(new BlurbEditor());
mainPanel.revalidate();
//I've also tried all possible combinations of these too
//mainPanel.repaint();
//mainPanel.validate();
</code></pre>

<p>This unfortunately is not working. What am I doing wrong?</p>

Try
```
mainPanel.invalidate()
```
and then if necessary,
```
mainPanel.validate()
```
.  It also might be worth checking that you're doing this all in the event dispatch thread, otherwise your results will be spotty and (generally) non-deterministic.