GUI opens with Rstudio but not from command prompt using Rscript

Am trying to call R GUI script in java swing using rjava from windows10 command prompt. When I run the script it runs fine in Rstudio but when I run in the command prompt using R script the GUI window does not appear

The code written in java , I have called from R script and the GUI opens in the R studio but in command prompt using Rscript it does not work

Following is R code

library(rJava)
.jinit()
.jclassPath()
x <- .jnew("HelloJava1")
x$test()

Following is java swing code

import java.awt.*;
import javax.swing.*;

public class HelloJava1 extends JComponent {

public void test() {
        Runnable r = new Runnable() {
        public void run() {
            JFrame f = new JFrame("HelloJava1");
            // f.setSize(300, 300);  better to pack() the frame
            f.getContentPane().add(new HelloJava1());
            // pack should be AFTER components are added..
            f.pack();
            f.setVisible(true);
        }
      };
     // Swing GUIs should be created and updated on the EDT
     SwingUtilities.invokeLater(r);
     }    

@Override  // good practice..
    public void paintComponent(java.awt.Graphics g) {
    // always call super method 1st!
       super.paintComponent(g);
       g.drawString("Hello, Java!", 125, 95);
     }

// instead of setting the size of components, it is 
// better to override the preferred size.
@Override
    public Dimension getPreferredSize() {
      return new Dimension(300,300);
    }
  }

Following is the code using command prompt

D:\Esurveyingsofttech\elevation>"C:\Program Files\R\R-3.6.1\bin\x64\Rscript.exe" D:\\Esurveyingsofttech\\elevation\\TestSwingGui.R

Java swing code opens a GUI in R studio , similarly when we run using Rscript the GUI should open. Any help is highly appreciated

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.