How do I use MiG Layout with Eclipse?

Josh Leitzel picture Josh Leitzel · May 2, 2009 · Viewed 9k times · Source

I've been Googling and checking on Stack Overflow and nothing has helped... hopefully someone can.

I usually just write my code by hand, but I'm working on a Java project that has a GUI aspect and I like what MiG Layout has to offer so I want to use it. I've downloaded the .jar file from the website, but I can't seem to be able to access it from my project.

I'm using Eclipse now as my IDE for this project because I don't want to have to deal with this particular thing by hand. I'm new to Eclipse, but here's what I've been trying: import the .jar file (via the Import tool for the project), then add the following code to my files:

import net.miginfocom.swing.MigLayout;
import javax.swing.*;

According to this page, this should work, right?

But when I try to run the program, I'm met with this message:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    MigLayout cannot be resolved to a type

What am I doing wrong?

Answer

Jon Skeet picture Jon Skeet · May 2, 2009

It sounds like the "import tool" part didn't work properly - that Eclipse isn't actually using the jar file.

I suggest you right-click on the project, choose Properties, and go to the Build Path page. Look under the "Libraries" tab. Assuming the jar file isn't there, add it and all should be well.