Rohan Rohan - 1 year ago 74
Java Question

How to create hyperlink to other stage from the text area

In JAVAFX application there is one text area in which i want to create the hyperlink so that after clicking on that hyperlink new stage will be open at run time(which will contain one text area) and text currently coming to main text area will be forwarded to new text area of new stage.Is this achievable? any suggestion?

I am having below code in my application where "actLogTArea" is the text area in which i want to give the hyperlink/button and from which i want to transfer the text coming to main text area to new text area can you suggest how this can be changed?

new Thread(new Runnable() {
protected Logger logger = Logger.getLogger(UnixBoxTask.class.getName());

public void run() {

try {

String user = userName;
String pass = pwd;
String host = lanIP;

JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);

java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");


BufferedReader br = new BufferedReader(new FileReader(scriptPath));
String line;
String command_cd = "";

// Build unix command list separated by semicolon
while ((line = br.readLine()) != null) {
if (line.charAt(0) == '.' && line.charAt(1) == '/') {
line = ". " + line;
command_cd += line + ";";

ArrayList nameofthreads = new ArrayList();

StringBuilder outputFromUnix = new StringBuilder();"Command = " + command_cd);
Channel channel = session.openChannel("shell");

if (taskName.equalsIgnoreCase(increseSRB) || taskName.equalsIgnoreCase(decreseSRB)) {
String keyValueFile = DeploymentTaskController.getInstance().scriptFilePath + "\\" + taskName + "_KeyValue.txt";
buildParameterList(keyValueFile, taskName);
ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp");
copyFiles(channelSftp, new File(keyValueFile), GlobalValues.getValueFromProps(taskName, "Build Path", LoginController.environment) + "/" + taskName);

PrintStream commander = new PrintStream(channel.getOutputStream(), true);
BufferedWriter bw = null;
InputStream outputstream_from_the_channel = channel.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(outputstream_from_the_channel));
bw = new BufferedWriter(new FileWriter(resultLogFile.getAbsolutePath(), true), 20000);

String jarOutput;
int count=0;

while ((jarOutput = reader.readLine()) != null) {"Status Update = " + jarOutput);

if (jarOutput.contains("Test")) {


// Display in activity log area in realtime.
if (DeploymentTaskController.actLogTArea != null && !taskName.equalsIgnoreCase(connectBundle)) {
final String outputStr = outputFromUnix.toString();
Platform.runLater(new Runnable() {
public void run() {





do {
} while (!channel.isEOF());



} catch (JSchException jex) {
System.out.println("JSCH Exception : " + jex.getMessage());
} catch (Exception ex) {

System.out.println("General Exception JSCH Block : " + ex.getMessage() + AppUtil.stack2string(ex));


Answer Source

It is very easy to achieve. And actually, hyperlink is not the thing, which to be used for that. Don't muff javafx and html.

What to do:

  1. create a button (hyperlink, if you want)
  2. setOnAction(new EventHandler<ActionEvent>(){}) and add the next code into the function:
  3. new Stage(new Scene(new Group(new TextArea(ta.textProperty().bind(ta.textProperty()))))).show(), where ta - is a text area from your first stage.

You have to note, that JavaFX is an object oriented GUI technology, and you can create new javaFx component object at any time, and update existing one at any time, when you have an access or link on it. Another important concept, which is usefull for you - properties. Property contain the value of some time. And properties can be binded - when value from one property is automaticaly propogated to another binded properties. Each javafx component (controls/layouts) interfaces are based on properties usage.

Button b = new Button("Create new console");
b.setOnAction(new EventHandler<ActionEvent>(){
    ... action() {
        new Stage(new Scene(new Group(new TextArea(DeploymentTaskController.actLogTArea.getText()))))).show();

Instead of DeploymentTaskController.actLogTArea you will have to create a kind of hash map, to decide, which text area to chose to add new content in :

DeploymentTaskController.actLogTAreaHashMap.get(<some key, to determine text area>);

and add new text area there, when you create new one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download