{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

layouts - Layout Managers Once we start adding more than...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Layout Managers Once we start adding more than one component to a container, we need to consider how we organize/arrange them. For this purpose, we can use layout managers. A layout manager is an object that determines the manner in which components are arranged in a container. Here is a list of commonly used layout managers: (they are defined in java.awt package.) BorderLayout – it organizes components into five areas (North, South, East, West, and Center). FlowLayout – it organizes components from left to right, starting new rows as necessary. GridLayout – it organizes components into a grid of rows and columns BoxLayout – it organizes components into a single row or a single column. CardLayout – it organizes components into one such that only one is visible at any time. GridBagLayout – it organizes components into a grid of cells, allowing components to span more than one cell.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
import javax.swing.*; // to use JApplet import java.awt.*; // to import FlowLayout manager public class AppletFlow extends JApplet { public void init() { Container content = getContentPane(); // to use FlowLayout to add components content.setLayout(new FlowLayout()); // create three buttons Button button1 = new Button("Button1"); Button button2 = new Button("Button2"); Button button3 = new Button("Button3"); // add three buttons to the content pane of JApplet object content.add(button1); content.add(button2); content.add(button3); setSize(270,70); } } An Example of Applet using FlowLayout This program using FlowLayout organizes three buttons in the following manner. If a user narrows the size of the applet, any component that did not fit in the first row will appear in the next row and so on.
Image of page 2
An Example of Applet using BorderLayout import javax.swing.*; // to use JApplet import java.awt.*; // to import BorderLayout manager public class AppletBorder extends JApplet { public void init() { Container content = getContentPane(); // to use BorderLayout to add components content.setLayout(new BorderLayout()); // create five buttons Button button1 = new Button("Button1"); Button button2 = new Button("Button2"); Button button3 = new Button("Button3");
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern