E ai galera!
Eu venho estudando Inteface feita na “unha” e até é legal, mas na hora dos alinhamentos não é bem assim.
Tenho uma janela feita na “unha” e outra feita no NB, gostaria de saber o que faço no código pra deixar ela igual a feita pelo NB.
[code]package Tela;
import java.awt.;
import java.awt.;
import javax.swing.*;
class ClienteFrame extends JFrame {
public ClienteFrame() {
super(".:: Web Server ::.");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(500, 30, 400, 300);
setLayout(new FlowLayout(FlowLayout.CENTER));
add(new ClientePane());
setVisible(true);
}
public static void main(String[] args) {
new ClienteFrame();
}
class ClientePane extends JPanel implements ActionListener {
JLabel ipL = new JLabel("Ip: ");
JLabel portaL = new JLabel("Porta: ");
JLabel arquivoL = new JLabel("Arquivo: ");
JTextField ipF = new JTextField(15);
JTextField portaF = new JTextField(10);
JTextField arquivoF = new JTextField(20);
JTextArea textArea = new JTextArea(10, 25);
JCheckBox ipCheck = new JCheckBox();
JCheckBox portaCheck = new JCheckBox();
JButton btnConectar = new JButton("Conectar", new ImageIcon(getClass().getResource("/conect.png")));
JButton btnLimpar = new JButton("Limpar", new ImageIcon(getClass().getResource("/limpar.png")));
GridBagLayout bag = new GridBagLayout();
public ClientePane() {
setLayout(bag);
addComponent(ipL, 0, 0, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
addComponent(ipF, 1, 0, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
addComponent(ipCheck, 2, 0, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
addComponent(portaL, 0, 1, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
addComponent(portaF, 1, 1, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
addComponent(portaCheck, 2, 1, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
addComponent(arquivoL, 0, 2, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
addComponent(arquivoF, 1, 2, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
addComponent(textArea, 1, 3, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.WEST);
addComponent(btnConectar, 0, 4, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
addComponent(btnLimpar, 1, 4, 1, 1, 1, 1, GridBagConstraints.NONE, GridBagConstraints.EAST);
}
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
void addComponent(Component component, int gridx, int gridy, int gridwidth, int gridheight, int weightx, int weighty, int fill, int anchor) {
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = gridx;
constraints.gridy = gridy;
constraints.gridwidth = gridwidth;
constraints.gridheight = gridheight;
constraints.weightx = weightx;
constraints.weighty = weighty;
constraints.fill = fill;
constraints.anchor = anchor;
bag.setConstraints(component, constraints);
add(component);
}
}
}
[/code]
- Já vejo pessoas falando: “Pra que fazer código na unha?”
Abraço… =]