jButton state does not changes at first click

requirement of flow is that when jButton1 is pressed

if it has text "Check" then execute second if statement

and is it has text "Refresh" then

have to execute first if statement.

The problem is that when jButton1 has text "Refresh" it executes first if condition and refreshes the jTextField1, choice1, and jTextArea1 but does not changes the states of buttons as required

if(!(recPresent) || jButton1.getText().equals("Refresh"))

{

jButton1.setText("Check");

jButton4.setEnabled(false);

jButton2.setEnabled(true);

part of if condition.

plz some one point out that why buttons dont change their state.

And if i press jButton1 second time then buttons change state as required.

but y not at first time?

Following is code used..................

publicvoid jButton1_mouseClicked(MouseEvent e)

{

boolean recPresent =false;

if (!(jTextField1.getText().equalsIgnoreCase("")))

recPresent = Connect.preCheck(jTextField1.getText());

if(!(recPresent) || jButton1.getText().equals("Refresh"))

{

jButton1.setText("Check");

jButton4.setEnabled(false);

jButton2.setEnabled(true);

jTextField1.setText("");

choice1.select(0);

jTextArea1.setText("");

}

if (recPresent && jButton1.getText().equals("Check") )

{

jButton1.setText("Refresh");

jButton4.setEnabled(true);

jButton2.setEnabled(false);

choice1.select (Connect.getReason(jTextField1.getText()));

jTextArea1.setText(Connect.fetchComments(jTextField1.getText()));

recPresent =false;

}

}

[2583 byte] By [@tifa] at [2007-10-3 3:33:03]
# 1

Use the java.awt.EventQueue invokeLater method to place your GUI changes on the event dispatch thread. For example:

if (!(recPresent) || jButton1.getText().equals("Refresh"))

{

EventQueue.invokeLater(new Runnable() {

public void run() {

jButton1.setText("Check");

jButton4.setEnabled(false);

jButton2.setEnabled(true);

}

});

}

paternostroa at 2007-7-14 21:27:23 > top of Java-index,Java Essentials,New To Java...