Create graphical interface using MigLayout

2

I need to create this graphical interface:

ThelastcodeItriedwasthis:
(butthesettingsarenotcorrect)

frame.setLayout(newMigLayout("wrap","[grow]","[grow][]"));
 panelInfo.setLayout(new MigLayout(""));
 panelInfo.add(new JLabel("tessssssstteeetsssssssss"), "grow, pushx, pushy, wrap");

 //panelMenu.setLayout(new MigLayout("fill","[] [] []"));
 panelMenu.setLayout(new MigLayout(""));
 panelMenu.add(anterior,"align center");
 panelMenu.add(proximo,"align center");
 panelMenu.add(backMenu,"align right");

 frame.getContentPane().add(panelInfo);
 frame.getContentPane().add(panelMenu);
    
asked by anonymous 18.12.2014 / 18:24

1 answer

4

I would do a Layouts composition, to fix the components in the footer would use the BorderLayout and would put a panel in the position PAGE_END.

ThepanelofPAGE_ENDwouldalsobeoftheBorderLayouttype,soyoucansettheExitrightbutton(LINE_END),anditwouldhaveanotherpaneltoputthetwonavigationbuttons,thoseintheCENTERposition.Forthe%sof%softhebuttons,IwoulduseMigLayouttomakethemresponsive.

Thestructurelookslikethis:

The end result would look like this:

Code:

importjava.awt.BorderLayout;importjava.awt.EventQueue;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.border.EmptyBorder;importjavax.swing.JButton;importnet.miginfocom.swing.MigLayout;importjava.awt.Color;importjava.awt.Dimension;publicclassComposicaoDeLayoutsextendsJFrame{privatestaticfinallongserialVersionUID=1L;privateJPanelcontentPane;/***Launchtheapplication.*/publicstaticvoidmain(String[]args){EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{ComposicaoDeLayoutsframe=newComposicaoDeLayouts();frame.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/***Createtheframe.*/publicComposicaoDeLayouts(){setMinimumSize(newDimension(400,300));setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100,100,450,300);contentPane=newJPanel();contentPane.setBorder(newEmptyBorder(5,5,5,5));setContentPane(contentPane);contentPane.setLayout(newBorderLayout(0,0));JPanelpnlCenter=newJPanel();pnlCenter.setBackground(Color.WHITE);contentPane.add(pnlCenter,BorderLayout.CENTER);JPanelpnlSouth=newJPanel();contentPane.add(pnlSouth,BorderLayout.SOUTH);pnlSouth.setLayout(newBorderLayout(0,0));JPanelpnlBotoesNavegacao=newJPanel();pnlSouth.add(pnlBotoesNavegacao,BorderLayout.CENTER);pnlBotoesNavegacao.setLayout(newMigLayout("", "[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");
    }
}
    
18.12.2014 / 19:39