Results 1 to 2 of 2

Thread: BorderLayout

  1. #1
    Madoka is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default 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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default 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.
    Java 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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How to use BorderLayout
    By Daman12 in forum New To Java
    Replies: 15
    Last Post: 10-27-2011, 06:30 AM
  2. BorderLayout problem
    By TGH in forum New To Java
    Replies: 3
    Last Post: 05-27-2010, 10:51 PM
  3. BorderLayout
    By oneself in forum New To Java
    Replies: 3
    Last Post: 08-06-2009, 11:59 PM
  4. BorderLayout Demo
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:51 PM
  5. Help with BorderLayout
    By lenny in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 08:26 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •