Created
June 25, 2014 04:30
-
-
Save paulodiovani/a2cbc38cf3e9dbbff77a to your computer and use it in GitHub Desktop.
Uma tela padrão para posicionamento relativo de campos, apenas para teste de exibição de componentes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package exemplo; | |
| import javax.swing.*; | |
| import java.awt.*; | |
| /** | |
| * Created by diovani on 25/06/14. | |
| */ | |
| public class TelaExemplo extends JFrame { | |
| // padrões, para controlar posição dos campos | |
| private Integer larguraLabels = 200; | |
| private Integer larguraCampos = 400; | |
| private Integer alturaCampos = 30; | |
| private Integer distanciaCampos = 6; | |
| // controled a posição do último campo | |
| private Integer bordaInferior = 0; | |
| public TelaExemplo() { | |
| this.bordaInferior = this.distanciaCampos; // inicializa a borda inferior, deixando uma margem | |
| // contrução da tela | |
| this.setTitle( "Exemplos de componentes" ); | |
| this.setBounds(80, 120, this.larguraLabels + this.larguraCampos + this.distanciaCampos * 3, 480); | |
| this.setResizable(false); | |
| this.setLayout(null); | |
| Container painel = this.getContentPane(); | |
| // Aqui adiciona os campos | |
| this.addCampo(painel, "Campo texto", new JTextField()); | |
| // Exibe a janela | |
| this.setDefaultCloseOperation( DISPOSE_ON_CLOSE ); | |
| this.setVisible( true ); | |
| } | |
| private void addCampo(Container panel, String labelText, JComponent field) { | |
| JLabel label = new JLabel(labelText); | |
| label.setLabelFor(field); | |
| label.setBounds(this.distanciaCampos, this.bordaInferior, | |
| this.larguraLabels, this.alturaCampos); | |
| field.setBounds(this.distanciaCampos * 2 + this.larguraLabels, | |
| this.bordaInferior, this.larguraCampos, this.alturaCampos); | |
| panel.add(label); | |
| panel.add(field); | |
| this.bordaInferior += this.alturaCampos + this.distanciaCampos; | |
| } | |
| public static void main (String[] args) { | |
| new TelaExemplo(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment