Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Importing Alternate Layout Managers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Importing Alternate Layout Managers" Watch "Importing Alternate Layout Managers" New topic

Importing Alternate Layout Managers

Howard Bates

Joined: Feb 26, 2008
Posts: 8

I am trying to use different layout managers but I can't seem to get them to work. I run the JDK off of my jumpdrive and I use BlueJ as my IDE. I have put the Layout jar file in my jre/lib/ext folder and used the following code to access:

import java.awt.*;
import javax.swing.*;
import MigLayout.*;

public class MigTest
* Constructor for objects of class MigTest
public MigTest()
JPanel p = new JPanel(new MigLayout("", "[right]"));

p.add(new JLabel("General"), "split, span, gaptop 10");
p.add(new JSeparator(), "growx, wrap, gaptop 10");

p.add(new JLabel("Company"), "gap 10");
p.add(new JTextField(""), "span, growx");
p.add(new JLabel("Contact"), "gap 10");
p.add(new JTextField(""), "span, growx, wrap");

p.add(new JLabel("Propeller"),"split, span, gaptop 10");
p.add(new JSeparator(), "growx, wrap, gaptop 10");

p.add(new JLabel("PTI/kW"), "gap 10");
p.add(new JTextField(10), "");
p.add(new JLabel("Power/kW"), "gap 10");
p.add(new JTextField(10), "wrap");
p.add(new JLabel("R/mm"), "gap 10");
p.add(new JTextField(10), "wrap");
p.add(new JLabel("D/mm"), "gap 10");
p.add(new JTextField(10));

I get the error on my import statement for miglayout. I have also edited my CLASSPATH to point directly to the jar file, but to no avail.


Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199


Welcome to JavaRanch!

The point of "import" is to tell the compiler that a class is in so-and-so package. A package is essentially a named group of classes. Using "import" lets you refer to a class in a package without using the package name each time.

I had to Google it, but apparently MigLayout is a class in the package "net.miginfocom.swing", so the correct import statement would be

[Jess in Action][AskingGoodQuestions]
Howard Bates

Joined: Feb 26, 2008
Posts: 8
Thank you for your quick reply!

I just tried it, but I got the following error:

Package net.miginfocom.swing does not exist.

So close......


Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
Putting the jar file in the jre/lib/ext directory will mean that the JVM will pick it up when you run the program, but the java compiler probably won't (it has it's own version of the jre).
You say you put the jar in the classpath as well. Show us your new classpath - you may have made a mistake there.
You should also check that the jar file actually contaisn the class you are looking for - you can open it up with any zip utility to check this.

Howard Bates

Joined: Feb 26, 2008
Posts: 8
Thanks for the help folks!

I changed:

import net.miginfocom.swing.MigLayout;


import net.miginfocom.swt.MigLayout;

and I get this error:

Cannot access org.eclipse.swt.widgets.Layout


Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
What a nuisance.

Have you got that eclipse folder in your CLASSPATH? Can you find it on your PC at all? If you can find it, read this, and look for classpath. You end up saying something like "java -cp C:\myfolder\subfolder\EclipseLayouts.jar myApp"
Have a look at the documentation for the Mig layouts; it may tell you where you can get the Eclipse file from. If the package name starts with org.miginfocom then you ought to find details on If that doesn't help, I am not sure what else to suggest, but somebody else will probably have an idea. Good luck.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Cannot access org.eclipse.swt.widgets.Layout
Did you take that jar file out of your extensions directory (jre/ext/lib) yet? Classes that are in the extensions directory can be accessed from your classpath, but they can't access classes that are in your classpath. That's why using the extensions directory isn't always such a good idea. I've been burnt by that twice in the past, I don't do it any more.
I agree. Here's the link:
subject: Importing Alternate Layout Managers
It's not a secret anymore!