I would make a composition of Layouts, to fix the components in the footer would use Borderlayout and put a panel
at PAGE_END.
The panel
PAGE_END would also be of the Borderlayout type, to fix the Exit button on the right (LINE_END), and would have another panel
to place the two navigation buttons, these in the CENTER position. For the panel
s of the buttons, I would use Miglayout to make them responsive.
The structure would look like this:
The end result would be as follows:
Code:
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import net.miginfocom.swing.MigLayout;
import java.awt.Color;
import java.awt.Dimension;
public class ComposicaoDeLayouts extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ComposicaoDeLayouts frame = new ComposicaoDeLayouts();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ComposicaoDeLayouts() {
setMinimumSize(new Dimension(400, 300));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
JPanel pnlCenter = new JPanel();
pnlCenter.setBackground(Color.WHITE);
contentPane.add(pnlCenter, BorderLayout.CENTER);
JPanel pnlSouth = new JPanel();
contentPane.add(pnlSouth, BorderLayout.SOUTH);
pnlSouth.setLayout(new BorderLayout(0, 0));
JPanel pnlBotoesNavegacao = new JPanel();
pnlSouth.add(pnlBotoesNavegacao, BorderLayout.CENTER);
pnlBotoesNavegacao.setLayout(new MigLayout("", "[1,grow 2][100px][100px][1,grow 1]", "[40px]"));
JButton btnAnterior = new JButton("<< Anterior");
pnlBotoesNavegacao.add(btnAnterior, "cell 1 0,grow");
JButton btnProximo = new JButton("Proximo >>");
pnlBotoesNavegacao.add(btnProximo, "cell 2 0,grow");
JPanel pnlBotaoSair = new JPanel();
pnlSouth.add(pnlBotaoSair, BorderLayout.EAST);
pnlBotaoSair.setLayout(new MigLayout("", "[100px]", "[40px]"));
JButton btnSair = new JButton("Sair");
pnlBotaoSair.add(btnSair, "cell 0 0,grow");
}
}
Do you have to use Miglayout? To fix components in the footer I’m much more using Borderlayout and putting them in the South panel.
– Math