Results 1 to 4 of 4

Thread: Panels

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    1

    Panels

    hey, i'm having a bit of trouble using panels...
    when ever i try to use them i get a heap of errors, all i'm trying to do with them is too tidy up my applets layout.

    so could someone please give me some example code showing me how to use panels using a border layout with a just a textfield and a couple of buttons.

    thanx for any help you can give me.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Here is a quick example of using a panel. If im not mistaken, i think the default layout manager for a panel is the FlowLayout
    and the default layout manager for a content pane is the BorderLayout. For the frame you can either extend (subclass)
    WindowAdapter and just override a particuliar method or you can
    implement a WindowListener interface if you like.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    class panelExample extends WindowAdapter{
    public static void main(String args[]){

    JButton Button1 = new JButton("Button 1");
    JButton Button2 = new JButton("Button 2");
    JButton Button3 = new JButton("Button 3");

    JFrame jf = new JFrame("Panel Example");
    JPanel jp = new JPanel();
    Container content = jf.getContentPane();
    content.setLayout(new BorderLayout());

    jp.add(Button1);
    jp.add(Button2);
    jp.add(Button3);

    content.add(jp, BorderLayout.SOUTH);

    jf.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    });

    jf.setSize(400,200);
    jf.setVisible(true);
    }
    }

  3. #3
    Lively Member
    Join Date
    Jan 2000
    Posts
    69

    layout managers

    Hey Dilenger4,

    You are right in that...panels and applets have flowlayout by default. Frames (and containers) will have a borderlayout by default. I will make a list of places that will provide better explanation of gui components (esp w/ the use of borderlayout).

    Manoj

  4. #4

Posting Permissions

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



Click Here to Expand Forum to Full Width