Boa tarde, pessoal!
A visual ficou difernete no cabeçalho da tabela e tabela, já tentei procurar na internet e mesma coisa não encontrado.
veja os codigos em baixo.
public class LayoutTela extends JFrame implements ActionListener {
Container c;
JPanel cardNorte,cardCenter, cardSul;
private JLabel lblMatricula;
private JTextField txtMatricula;
private JLabel lblNomeProfessor;
private JTextField txtNomeProfessor;
final static String TXT1 = "Card 1 em norte";
final static String TXT2 = "Card 2 em Sul";
public LayoutTela() {
super("Layout");
c = getContentPane();
c.add(registro(), BorderLayout.NORTH);
c.add(tabela(), BorderLayout.CENTER);
c.add(botoes(),BorderLayout.SOUTH);
this.setContentPane(c);
this.pack();
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 400);
}
private JPanel registro() {
cardNorte = new JPanel(new GridLayout(3, 2, 5, 3));
lblMatricula = label("Matricula");
cardNorte.add(lblMatricula);
txtMatricula = textField(40);
cardNorte.add(txtMatricula);
lblNomeProfessor = label("Nome do Professor");
cardNorte.add(lblNomeProfessor);
txtNomeProfessor = textField(30);
cardNorte.add(txtNomeProfessor);
return cardNorte;
}
private JPanel botoes(){
cardSul = new JPanel(new BorderLayout());
cardSul.add(botao("Enviar"), BorderLayout.EAST);
cardSul.add(botao("Limpar"),BorderLayout.WEST);
return cardSul;
}
private JPanel tabela() {
cardCenter = new JPanel();
cardCenter.setLayout(new BorderLayout());
cardCenter.add(modeloTabela().getTableHeader(),BorderLayout.NORTH);
cardCenter.add(modeloTabela(), BorderLayout.CENTER);
return cardCenter;
}
public JTable modeloTabela() {
Object[] colunas = { "ID", "Nome", "Conceitos" };
Object[][] valores = new Object[3][3];
for (int i = 0; i < valores.length; i++) {
valores[i][0] = "Teste Coluna 1";
valores[i][1] = "Teste coluna 2";
valores[i][2] = new Boolean(false);
}
DefaultTableModel modelo = new DefaultTableModel(valores, colunas);
return new JTable(modelo);
}
public JLabel label(String nome) {
JLabel lbl = new JLabel(nome);
return lbl;
}
public JTextField textField(int tamanho) {
JTextField txt = new JTextField(tamanho);
return txt;
}
public JButton botao(String nome){
JButton button = new JButton(nome);
button.setActionCommand(nome.replace(" ","_" ).toLowerCase());
button.addActionListener(this);
return button;
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}
espero que vcs me ajuda… obrigado!