Skip to content

Instantly share code, notes, and snippets.

@ProgDan
Created August 31, 2012 17:49
Show Gist options
  • Select an option

  • Save ProgDan/3556444 to your computer and use it in GitHub Desktop.

Select an option

Save ProgDan/3556444 to your computer and use it in GitHub Desktop.
Exemplo: FlowLayout
import java.awt.*;
import javax.swing.*;
public class MinhaJanela extends JPanel {
public MinhaJanela(){
/* Conjunto de linhas (alinhamento à esquerda) */
//FlowLayout fluxo = new FlowLayout();
/* Conjunto de linhas (alinhamento à direita) */
//FlowLayout fluxo = new FlowLayout(FlowLayout.LEFT);
/* Conjunto de linhas (alinhamento centralizado,
com espaçamento entre os componentes */
FlowLayout fluxo = new FlowLayout(FlowLayout.CENTER, 5, 15);
setLayout(fluxo);
JButton btn;
for(int i=0; i<20; i++){
btn = new JButton("Botao "+(i+1));
add(btn);
}
}
}
import java.awt.*;
import javax.swing.*;
public class Principal extends JFrame {
public Principal() {
super("Minha Janela");
setSize(400, 300);
Container c = getContentPane();
MinhaJanela janela = new MinhaJanela();
c.add(janela);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new Principal();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment