Change Horizontal Gap for FlowLayout in Java
Description
The following code shows how to change Horizontal Gap for FlowLayout.
Example
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/* w w w. j a v a2s.c o m*/
public class Main {
public static void main(String[] args) {
FlowLayout flow = new FlowLayout(FlowLayout.LEFT, 20, 30);
JPanel panel = new JPanel(flow);
flow.setHgap(35);
JTextArea area = new JTextArea("text area");
area.setPreferredSize(new Dimension(100, 100));
JButton button = new JButton("button");
panel.add(button);
panel.add(new JScrollPane(area));
JFrame f = new JFrame();
f.add(panel);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »