-
BorderLayout
I my program there are going to be multiple panels that I want to layout nicely for the user. How can I set a Border Layout in a JPanel and the set that JPanel in a Border Layout on a JFrame.
Ok, that sounds a little confusing. Let's make that simpler. I need to set a Border Layout on a part of the program that only extends JPanel. How would I set a Border Layout for a JPanel?
Because I keep getting an error: non-static method setLayout(java.awt.LayoutManager) cannot be referenced from a static context
-
Re: BorderLayout
Nothing to do with JPanel or BorderLayout. Everything to do with your (need of) understanding of static vs non-static members.
Static methods are invoked on the class; non-static members on an instance of the class, created using the new keyword. Code:
class A {
public static void showStatic() {
System.out.println("static method");
}
public void showNonStatic() {
System.out.println("non-static method");
}
}
class B {
public static void main(String[] args) {
A.showStatic();
A a = new A();
a.showNonStatic();
}
}
Since this isn't really an AWT/Swing question, I'm moving it to New to Java.
db