Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importing Alternate Layout Managers

 
Howard Bates
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

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.

Thanks,

Howard
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

 
Howard Bates
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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......

Thanks!

~Howard
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help folks!

I changed:

import net.miginfocom.swing.MigLayout;

to:

import net.miginfocom.swt.MigLayout;

and I get this error:

Cannot access org.eclipse.swt.widgets.Layout

My CLASSPATH is:

.;E:\JAVA\BatesProjects\miglayout15-swt.jar;E:\JAVA\BatesProjects\riverlayout.zip;E:\JAVA\BatesProjects\tablelayout.jar
 
Campbell Ritchie
Sheriff
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 www.miginfocom.org. 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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic