Adding JPanels to exisiting program

I am new to swing and having a bit of trouble. I have created a very simple window using flowLayout but I would like to add some rows to it using the JPanels. I was wondering where the JPanel calls go, and how they should be called--in the main? Should each JPanel be it's own method? Could someone indicate in the code below where the calls should go? Can I replace the contentpane calls with a JPanel? Thanks for any help on this!!

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class FlowWindow extends JWindow {

boolean inAnApplet = true;

public FlowWindow() {

Container contentPane = getContentPane();

contentPane.setLayout(new FlowLayout());

contentPane.add(new JButton("Button 1"));

contentPane.add(new JButton("2"));

contentPane.add(new JButton("Button 3"));

contentPane.add(new JButton("Long-Named Button 4"));

contentPane.add(new JButton("Button 5"));

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

if (inAnApplet) {

dispose();

} else {

System.exit(0);

}

}

});

}

public static void main(String args[]) {

FlowWindow window = new FlowWindow();

window.inAnApplet = false;

window.setTitle("FlowLayout");

window.pack();

window.setVisible(true);

}

}

[1424 byte] By [marc34] at [2007-9-26 2:15:38]
# 1

if you like to add some rows. it is easier this:

[code]

...

Container contentPane = getContentPane();

contentPane.setLayout(new GridLayout(3,1)); // three rows and one column

...

[code]

you can add to the three rows JPanels and then add the button to the panels. Layout Manager's JPanel is FlowLayout (default).

Hope this helps

R2D2 at 2007-6-29 9:13:01 > top of Java-index,Archived Forums,Swing...