galera, tenho dois métodos q criam botoes dentro do mesmo painel.
mas ele tem q remover todos os componentes antes de mostrar o outro painel.
do jeito q tá, qdo executa o método mostraAberturaConta();
ele mostra em cima do outro, mostrando componentes do outro painel.
private void jCpdvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCpdvActionPerformed
jCpdv = (JComboBox)evt.getSource();
String nomePDV = (String)jCpdv.getSelectedItem();
if (nomePDV.equals("RECEPÇÃO")) {
try {
jPmovGeral.removeAll();
mostraChartPDV();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
else {
try {
jPmovGeral.removeAll();
mostraAberturaConta();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
public void mostraChartPDV() throws SQLException {
jPmovGeral.setLayout(new GridLayout (7,7));
final Icon iconDisponivel = new ImageIcon("/Documents and Settings/User/Desktop/desktop/icones/portaaberta2.jpg");
final Icon iconOcupado = new ImageIcon("/Documents and Settings/User/Desktop/desktop/icones/ocupada.gif");
ResultSet rs = null;
this.con = pacote_util.Conexao.getConexao();
try{
PreparedStatement pstm = this.con.prepareStatement("SELECT * FROM situacao_unidade");
rs = pstm.executeQuery();
while(rs.next()){
situacao = rs.getString("NomeSituacao");
numero = rs.getString("UNIDADE_NumeroUnidade");
NumeroUnidades[i] = numero;
botoes[i] = new JButton(NumeroUnidades[i]);
jPmovGeral.add(botoes[i]);
botoes[i].setBackground(White);
botoes[i].addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
if (e.getSource() instanceof JButton) {
numUnid = ((JButton)e.getSource()).getText();
jTunidade.setText(numUnid);
jTsituacao.setText(situacao);
if (situacao.equals("DISPONÍVEL")) {
visTipoUnid(numUnid);
}
else {
visMovUnid(numUnid);
visMovimento(numUnid);
}
}
}
});
if (situacao.equals("DISPONÍVEL")) {
botoes[i].setIcon(iconDisponivel);
}
else {
botoes[i].setIcon(iconOcupado);
}
i++;
}
}catch(Exception e){
e.printStackTrace();
}
}
public void mostraAberturaConta() throws SQLException {
String NumeroUnidades [] = new String [49];
String numero, numMesas = "";
jPmovGeral.setLayout(new GridLayout (7,7));
final Icon iconMesa = new ImageIcon("/Documents and Settings/User/Desktop/desktop/icones/mesa.gif");
ResultSet rs = null;
this.con = pacote_util.Conexao.getConexao();
try{
PreparedStatement pstm = this.con.prepareStatement("SELECT NumeroUnidade FROM abertura_conta");
rs = pstm.executeQuery();
while(rs.next()){
numero = rs.getString("NumeroUnidade");
NumeroUnidades[i] = numero;
botoes[i] = new JButton(NumeroUnidades[i]);
botoes[i].setIcon(iconMesa);
// jPmovGeral.removeAll();
jPmovGeral.add(botoes[i]);
botoes[i].setBackground(White);
botoes[i].addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
if (e.getSource() instanceof JButton) {
numUnid = ((JButton)e.getSource()).getText();
jTunidade.setText(numUnid);
// visTipoUnid(numUnid); visMovUnid(numUnid); visMovimento(numUnid);
}
}
});
i++;
}
}catch(Exception e){
e.printStackTrace( );
}
}