Rabu, 13 Agustus 2025

JAVA - Flow Layout

 





/*

 * To change this license header, choose License Headers in Project Properties.

 * To change this template file, choose Tools | Templates

 * and open the template in the editor.

 */

package tflowlayout;

import javax.swing.*;

import java.awt.*;


public class TFlowLayout extends JApplet {

    Container container = null;


    public void init() {

       // 1. Get the handle on applet's content pane.

       container = this.getContentPane();


       // 2. Create the flow layout object and set it for the applet.

       FlowLayout fl = new FlowLayout(FlowLayout.LEFT, 5, 10);

                 // horizontal gap = 5 pixels, vertical gap = 10 pixels

                          

       container.setLayout(fl);


       // 3. Create and add some buttons to the applet.

       for (int i=0; i<4; i++) {

          JButton button = new JButton("Button"+(i+1));

          button.setPreferredSize(new Dimension(100,25)); // width=100, height=25

          container.add(button);

       }

    }

}


Tidak ada komentar: