Frank Winkler
Frank Winkler

Reputation: 419

Set TextArea text dynamically by script

This a follow-up question to Console output on Installation screen?

I've configured a screen that contains a Text area component ("log.display") that should display what happened during my installation. The installation runs in a script that is attached to this screen. After finishing an installation step I do something like this (displayLog is initialized before):

    displayLog = displayLog + currentStep + " done. \n";
    context.setVariable("log.display",displayLog);

Unfortunatelly the Text area component is not updated by this. What can (must) I do to update the Text area dynamically from my script?

EDIT:

I found:

    formPanelContainer = (FormPanelContainer)context.getScreenById(<screenID>); 
    formPanelContainer.getFormEnvironment().reinitializeFormComponents(); 

this seems to work, but there is one problem with that: If the "log" displayed with this solution contains more lines than the Text area can display, it shows the vertical scrollbar but doesn't scroll to the last line automatically. Is there a way to let the Text area do that?

And another question: Is it possible to ask context for the current screen without specifying a screenID (what can change)?

thanks! Frank

Upvotes: 1

Views: 376

Answers (1)

Frank Winkler
Frank Winkler

Reputation: 419

The solution for my problem seems to be: get the ConfigurationObject of the TextArea component:

FormPanelContainer formPanelContainer = (FormPanelContainer)context.getScreenById(<ScreenID>);
FormEnvironment formEnvironment = formPanelContainer.getFormEnvironment();
FormComponent logComponent = formEnvironment.getFormComponentById(<TextAreaComponentID>);
JTextArea logComponentObject = (JTextArea)logComponent.getConfigurationObject();

and each time, something has to be logged:

logComponentObject.append("Text to log" + "\n");
logComponentObject.setCaretPosition(logComponentObject.getDocument().getLength());

This works fine in my setup.

Upvotes: 1

Related Questions