-
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.
-
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);
}
}
-
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
-
cool. Thanks........ I wasnt to sure about what defaults were. This
is the best explanation of Layout Managers ive seen so far.
http://java.sun.com/docs/books/tutor...out/using.html