public class Primary extends JFrame {
public Primary(String title) {
super(title);
JLabel Label1 = new JLabel("hello");
Container c= getContentPane();
c.add(Label1, new AbsoluteConstraints(117,15));
}
}
I have written this code having invoked runnable JFrame
in the main class.
However although no errors are showing, I'm getting lots of errors when trying to compile.
The error is long but here is a sample of it:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string (or null) at java.awt.BorderLayout.addLayoutComponent(BorderLayout.java:426) at javax.swing.JRootPane$1.addLayoutComponent(JRootPane.java:531) at java.awt.Container.addImpl(Container.java:1120)"
- First of all i want to point it out that BorderLayout
is the default layout for JFrame
.
- And you need to explicitly change the Layout
to be used, if you don't want the default BorderLayout
.
- If possible use the Group Layout
developed by NetBeans
Team back in 2005, Its simply awesome. Use the Windows Builder Pro
tool which is now freely available from Google.