Vc poderia usar o método remove(Component c) e depois usar o repaint(), para atualizar as modificações.
 
Falow
----- Original Message -----
From: Edson
Sent: Thursday, February 06, 2003 7:22 PM
Subject: [java-list] Como faço para remover um campo de um painel e atualizar a tela do usuário sem esse componente ????

Pessoal,
 
 
Estou estudando java e gostaria de saber seguinte :
 
Como faço para remover um campo da tela do usuário ???
Gostaria de tirar o lblcodcliente da tela.
Alguém poderia ajudar ???
 
Essa é uma classe de estudo.
Gostaria de aprender esse conceito.
Obrigado.
 
 
*********************************************************************
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
 
public class Pesquisa2 extends JDialog
   implements ActionListener,Runnable
{
 
 private Thread tr = null;
 
 private static Pesquisa2 app = null;
 
 private Container c;
 
 private JButton btnPesquisar;
 private JTextField txtcodcliente;
 public JLabel lblcodcliente;
 
 private JPanel p = new JPanel();
 
  
 public Pesquisa2()
 {
 
  initform();
 }
 
 
 public void initform()
 {
  setTitle("Pesquisa2");
  
  JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
  p.setLayout(null);
  
  
  lblcodcliente = new JLabel("Digite o código do usuário: ");
  lblcodcliente.setBounds(0,0,180,25);
  
  txtcodcliente = new JTextField("",10);
  txtcodcliente.setBounds(152,0,100,25);
  
  btnPesquisar = new JButton("Pesquisar");
  btnPesquisar.addActionListener(this);
  btnPesquisar.setBounds(252,0,100,25);
  
  p.add(lblcodcliente);
  p.add(txtcodcliente);
  p.add(btnPesquisar);
    
  c = getContentPane();
  c.setLayout(new BorderLayout());
  c.add(BorderLayout.CENTER,p);
  
  pack();
  setBounds(new Rectangle(0, 0, 400, 100));
 }
 
 
 public void run()
 {
 
  p.remove(lblcodcliente);
  p.repaint();
  
  System.out.println("Passei no run");
 }
 
 public void actionPerformed(ActionEvent e)
 {
  Object source = e.getSource();
  
  if (source == btnPesquisar)
        {
      if (tr != null)
      {
       tr = null;
      }
     
      tr = new Thread(this); 
            tr.start();
        }
 }
 
 public static void main(String[] args)
 {
  app = new Pesquisa2();
  app.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent we)
   {
    System.exit(0);
   }
  });
  app.show();
 }
}

Responder a