|
-
May 18th, 2001, 02:22 AM
#1
Thread Starter
New Member
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.
-
May 19th, 2001, 07:39 PM
#2
Dazed Member
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);
}
}
-
May 20th, 2001, 01:29 PM
#3
Lively Member
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
-
May 20th, 2001, 02:04 PM
#4
Dazed Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|