Universal Robots+

Showing an image in a URCap

As I am very new for the URcap, cloud you please tell me where are the right location to place these code, I guess the “openView():” is in ProgramNodeContribution.java but I have no idea about where are the “HTML side”. anyway if you can tell the right location may would help me very much.

the html Files in the URCap examples are located in src/main/resources/com.urcapexample.impl. I would suggest following the Instructions covered in the urcap_tutorial_html.pdf File in your SDK’s doc Folder :wink:

Thanks for your help, but I can’t see the html files in that path / normally I type my code in java files as following starter package and never use html before.

could you please give me an example or screenshot? I am much appreciate

my project screenshot is shown below.

Capture

the html file is not included if you generate a new empty urcap with the sdk (sorry for confusion). Your html file should at least be implemented in the /resources Folder or in a Subfolder of /resources to call it with the getHTML() with this.getClass().getResourceAsStream… Function in your ProgramNodeService. The Above mentioned Folder was for the urcap examples.

Continuing the discussion from Showing an image in a URCap:

Hi,

I try to use Img component as above but I got an error as below

2019-09-25_11-52-28

Could you guy please help me figure out?

Note: I have been try in Hello world HTML example and it’s worked but now I try to combine in my project file which is created follow starter package and never use the HTML code before. I guess it may cause by it

Have you verified the id in the HTML id match?

<img src=“none.png” id=“liveImage2>

I have been verified as below

2

and also I refer this HTML in ProgramNodeService as below

@Override
public InputStream getHTML() {
InputStream is = this.getClass().getResourceAsStream("/impl/programnode.html");
return is;
}

From the file structure on the left of the screenshot, i suspect that the issue is that you haven’t actually loaded the image into eclipse, as there is no image listed named none.png. If you have put the image in the projects resources folder, you need to refresh the resources folder in eclipse to make it appear. There is an image named ur.png I suspect that if you change the source in the html file to "ur.png" that you would see that image in your URCap.

As above it may not necessary, but anyway I try to do as you suggested so it still not work for me.

if you see others potential please tell me and I will try anyway as I can.

My memory tells me that I have experienced an issue when a <div> was in the end or alone.
I would try to add more html components before and after. Just for the test case.

Hi,

I tried this code, but it’s giving me an error at the end of the second line:
Syntax error on token “;”, expected

Where exactly are you putting this code? Im writing it in the root of the program node view.

I was using:

JLabel imgLabel = new JLabel(new ImageIcon("/home/ur/workspace/com.inmotion.Weld/src/main/resources/META-INF/logo.png"));

But it only worked within the simulator, on the Polyscope it didn’t work.

The file directory on the simulator compared to the physical robot are different.

Use the following line to load your image. Store the image within a resource folder of the java project.

ImageIO.read(getClass().getResource("/com/ur/urcap/helloworld/impl/ur.png"))

Thank you for your response, I tried this line already, but I got that error that I mentioned above:

Syntax error on token “;”, expected (In the end of the BufferedImage line)

I entered this in the root of the ProgramNodeView:

public JLabel imageLabel;
BufferedImage image = ImageIO.read(this.getClass().getResource(“image.png”));
imageLabel = new JLabel(new ImageIcon(imageLabel));

EDIT:
I put these lines inside a box construction method that I created, now the error I am getting is:

The constructor ImageIcon(JLabel) is undefined.

JLabel imageLabel;
BufferedImage image = ImageIO.read(getClass().getResource("/ur.png"));
imageLabel = new JLabel(new ImageIcon(imageLabel));

Now I am getting the error:

The method setImage(BufferedImage) is undefined for the type JLabel

setImage() is not the method you’re looking for, what you need is the following:

imageLabel.setIcon(new ImageIcon(image));

where image is the BufferedImage that you have fetched from the resources folder.

My original comment is incorrect (frustratingly, for whatever reason, I can’t edit it), as I try to set the imageIcon of of a JLabel as the JLabel itself, which is nonsensical. You need to specify the BufferedImage (in your case, image) as the argument for new ImageIcon().

1 Like

Thank you very much Sam!!

Now it makes senses and it finally worked!!

1 Like

Hello Sam,

I tried the following code said above and i found out this when i installed the URCap on the polyscope.

How do i solve this problem?

From the Oracle doc on the NullPointerException:

Thrown when an application attempts to use null in a case where an object is required. These include:

  • Calling the instance method of a null object.
  • Accessing or modifying the field of a null object.
  • Taking the length of null as if it were an array.
  • Accessing or modifying the slots of null as if it were an array.
  • Throwing null as if it were a Throwable value.

It is likely that you have got your reference for your image wrong, or that your image is in the wrong place in your eclipse project. You should store your images in the resources folder and check the references to the image.

1 Like

On Swing:

JPanel temp= new JPanel();
BufferedImage logoImage;
java.io.InputStream imageStream3 = this.getClass().getResourceAsStream("/YOURIMAGE.png");
try {
logoImage = ImageIO.read(imageStream3);
JLabel logo = new JLabel(new ImageIcon(logoImage));
temp.add(logo, Box.LEFT_ALIGNMENT);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

	}		

}

temp variable will hold your image.
and place that image under your resources folder.

1 Like