I am trying to update the jtextarea after displaying JDialog but it is not updating can anyone help me.
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setBounds(0, 0, 500, 500);
frame.setVisible(true);
JDialog dialog = new JDialog(frame);
dialog.setModal(true);
JPanel panel = new JPanel();
dialog.add(panel);
final JTextArea area = new JTextArea();
panel.add(area);
dialog.setBounds(100, 100, 200, 200);
area.setLineWrap(true);
area.setText("bbbbbbbbbbbb");
dialog.setVisible(true);
area.setText("zzzz");
}
The call to
dialog.setVisibleis blocking. This means that the statementarea.setText("zzzz")will not be executed until AFTER the dialog is closed.This is simply the nature of modal dialogs
UPDATE
In order to be able to update the UI like this, you need to be a little sneaky…