public static TextArea message_text=new TextArea();
final static String message_text_style="-fx-border-width: 5px;-fx-border-radius: 10px;-fx-border-style: solid;-fx-border-color: #ff7f7f;";
private static int timer;
public static void system_message(String what,int set_timer)
{
timer=set_timer;
message_text.setText(what);
message_text.setStyle("-fx-opacity: 1;"+message_text_style);
Platform.runLater(new Runnable()
{
public void run()
{
try
{
Thread.sleep(timer);
}
catch(InterruptedException ex)
{
}
message_text.setStyle("-fx-opacity: 0;"+message_text_style);
}
});
}
This code is aimed at a message pop up appearing and then disappearing after a certain amount of time ( so that system events can be communicated to the user ). This is realized by setting the opacity of a TextArea element so that it becomes visible. The runLater block is responsible for switching the opacity back after a set amount of time.
This is an example where I invoke this method:
Button save_as_pgn_button=new Button();
save_as_pgn_button.setText("Save as: ");
save_as_pgn_button.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
String path=pgn_name_text.getText();
if(path.length()>0)
{
MyFile my_file=new MyFile(path);
calc_pgn();
my_file.content=pgn;
my_file.write_content();
Javachessgui.system_message("Saved to file: "+path+"\n\nContent: "+my_file.content,3000);
}
}
});
The frightening thing is that it sometimes works, sometimes not. Mostly not, but sometimes when I press the button it works exactly as expected. Or if I run it in debug mode and toggle a breakpoint before system_message() and then step over it, it always works!
What is going on?