CardLayout.setHgap(int hgap) has the following syntax.
public void setHgap(int hgap)
In the following code shows how to use CardLayout.setHgap(int hgap) method.
import java.awt.CardLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; //from ww w .j a v a 2s . c o m import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Main { public static void main(String[] args) { JFrame aWindow = new JFrame(); aWindow.setSize(400, 400); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); aWindow.add(new CardLayoutPanel()); aWindow.setVisible(true); } } class CardLayoutPanel extends JPanel implements ActionListener { CardLayout card = new CardLayout(50, 50); public CardLayoutPanel() { setLayout(card); JButton button; for (int i = 1; i <= 6; i++) { add(button = new JButton("Press " + i), "Card" + i); button.addActionListener(this); } card.setVgap(50); card.setHgap(30); } public void actionPerformed(ActionEvent e) { card.next(this); } }