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
BorderLayoutis the default layout forJFrame.– And you need to explicitly change the
Layoutto be used, if you don’t want the defaultBorderLayout.– If possible use the
Group Layoutdeveloped byNetBeansTeam back in 2005, Its simply awesome. Use theWindows Builder Protool which is now freely available from Google.