import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FlowLayoutSettingGaps {
public static void main(String[] args) {
JFrame aWindow = new JFrame("This is a Flow Layout");
aWindow.setBounds(30, 30, 300, 300); // Size
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flow = new FlowLayout(); // Create a layout manager
flow.setHgap(35); // Set the horizontal gap
Container content = aWindow.getContentPane(); // Get the content pane
content.setLayout(flow); // Set the container layout mgr
// Now add six button components
for (int i = 1; i <= 6; i++) {
content.add(new JButton("Press " + i)); // Add a Button to content pane
}
aWindow.setVisible(true); // Display the window
}
}
|