Toolbar does not show components

Hi,

I am trying to develope a URCap with an InstallationNode and a Toolbar. I finished the developement of the InstallationNode and just wanted to start the developement of the toolbar with soma basic swing components but the toolbar remains empty.

Then I simplified my code and printed some lines to debug.

Here is some of my Code…
The Activator:

public class ToolbarContribution implements SwingToolbarContribution{
	
	private static final int HEADER_FONT_SIZE = 16;
	
	private final ToolbarContext context;
	
	ToolbarContribution(ToolbarContext context) {
		this.context = context;
		System.out.println("//////////  ToolbarContribution initialized.  ///////////");
		
	}
	
	@Override
	public void openView() {

		System.out.println("Opening Toolbar View...");
	}
	
	@Override
	public void closeView() {

		System.out.println("Closing Toolbar View...");
	}

	@Override
	public void buildUI(final JPanel jPanel) {
		
		System.out.println("Building Toolbar UI...");
		
	    javax.swing.SwingUtilities.invokeLater(new Runnable() {
	        @Override
	        public void run() {
	            jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
	            JLabel label = new JLabel("Welcome to this Toolbar");
	            label.setFont(new Font("Arial", Font.BOLD, HEADER_FONT_SIZE));
	            jPanel.add(label);

	            jPanel.revalidate();
	            jPanel.repaint();
	        }
	    });
	}

The ToolbarService:

public class ToolbarService implements SwingToolbarService {
	
	@Override
	public Icon getIcon() {
		return new ImageIcon(getClass().getResource("/icons/ruhrbotics_logo.png"));
	}
	
	@Override
	public void configureContribution(ToolbarConfiguration configuration) {
		configuration.setToolbarHeight(400);
	}
	
	@Override
	public SwingToolbarContribution createToolbar(ToolbarContext context) {
		
		System.out.println("Creating SwingToolbarContribution...");
		
		return new ToolbarContribution(context);
	}

}

And the ToolbarContribution:

public class ToolbarContribution implements SwingToolbarContribution{
	
	private static final int HEADER_FONT_SIZE = 16;
	
	private final ToolbarContext context;
	
	ToolbarContribution(ToolbarContext context) {
		this.context = context;
		System.out.println("//////////  ToolbarContribution initialized.  ///////////");
		
	}
	
	@Override
	public void openView() {

		System.out.println("Opening Toolbar View...");
	}
	
	@Override
	public void closeView() {

		System.out.println("Closing Toolbar View...");
	}

	@Override
	public void buildUI(final JPanel jPanel) {
		
		System.out.println("Building Toolbar UI...");
		
	    javax.swing.SwingUtilities.invokeLater(new Runnable() {
	        @Override
	        public void run() {
	            jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
	            JLabel label = new JLabel("Welcome to this Toolbar");
	            label.setFont(new Font("Arial", Font.BOLD, HEADER_FONT_SIZE));
	            jPanel.add(label);

	            jPanel.revalidate();
	            jPanel.repaint();
	        }
	    });
	}

With this I was able to find out that the buildUI() method does not run. But for now I am stuck. Here is part of my terminal after starting and closing ursim:

PROFINET registering!
10:47:07.214 WARN - Method used before correct value has been received from controller, returning default = joint_max_speed {thread: Thread-4 , loggerClass: com.ur.polyscope.robot.configuration.joint.JointConfigurationSettings}
10:47:07.214 WARN - Ignoring any future reports of error {thread: Thread-4 , loggerClass: com.ur.polyscope.robot.configuration.joint.JointConfigurationSettings}
Nov 21, 2024 10:47:07 AM com.steadystate.css.parser.CSSOMParser
WARNING: java.lang.ClassNotFoundException: com.steadystate.css.parser.SACParserCSS21 not found by org.w3c.css.sac [170]
Nov 21, 2024 10:47:07 AM com.steadystate.css.parser.CSSOMParser
WARNING: using the default ‘SACParserCSS21’ instead
10:47:07.699 WARN - Not connected to controller, trying to send string:
sec load_installation():
step_count_3d9c06b7_afa1_40f5_acb6_8cac3f3f873b = 0.0
thread Step_Counter_Thread_db87e220_3e1b_4418_a761_a802b3244f53():
while (True):
step_count_3d9c06b7_afa1_40f5_acb6_8cac3f3f873b = step_count_3d9c06b7_afa1_40f5_acb6_8cac3f3f873b + 1.0
sync()
end
end
run Step_Counter_Thread_db87e220_3e1b_4418_a761_a802b3244f53()
set_standard_analog_input_domain(0, 1)
set_standard_analog_input_domain(1, 1)
set_tool_analog_input_domain(0, 1)
set_tool_analog_input_domain(1, 1)
set_analog_outputdomain(0, 0)
set_analog_outputdomain(1, 0)
set_input_actions_to_default()
set_gravity([0.0, 0.0, 9.82])
set_target_payload(0.000000, [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000])
set_tool_communication(False, 115200, 0, 1, 1.5, 3.5)
set_tool_output_mode(0)
set_tool_digital_output_mode(0, 1)
set_tool_digital_output_mode(1, 1)
set_tool_voltage(0)
set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])
set_safety_mode_transition_hardness(1)
end
{thread: Thread-4 , loggerClass: com.ur.polyscope.controllerinterface.internal.ControllerSocket}
10:47:12.588 ERROR - No help files found: Help is unavailable! {thread: AWT-EventQueue-0 , loggerClass: com.ur.view.help.HelpLoader}
10:47:30.401 ERROR - Disconnected and failed: {thread: ControllerConnectionThread , loggerClass: com.ur.polyscope.controllerinterface.internal.ControllerSocket$ConnectionThread}
java.lang.NullPointerException
at com.ur.polyscope.controllerinterface.internal.ControllerSocket$ConnectionThread.parseMessage(ControllerSocket.java:351) ~[polyscope-controllerinterface-impl-4.8.1.jar:?]
at com.ur.polyscope.controllerinterface.internal.ControllerSocket$ConnectionThread.performWhileConnected(ControllerSocket.java:326) ~[polyscope-controllerinterface-impl-4.8.1.jar:?]
at com.ur.polyscope.controllerinterface.internal.ControllerSocket$ConnectionThread.run(ControllerSocket.java:265) [polyscope-controllerinterface-impl-4.8.1.jar:?]
2024-11-21 10:47:30,512 FATAL Unable to register shutdown hook because JVM is shutting down.
10:47:30.512 ERROR - File attachment not found: /home/ur/ursim/ursim-5.11.0.108249/.urcontrol/daemon_ur/log/current {thread: pool-117-thread-1 , loggerClass: com.ur.polyscope.flightrecorder.internal.attachment.FlightRecorderTextFileAttachment}

Thanks in advance for your help.

Get rid of the invoke later wrapping of your buildUI method. Just let the method run immediately

I just implemented it to solve my problem but it did not help. Removing it does not help either.

I don’t see any of your println statements in the console. Can you confirm that the Toolbar Constructor is running properly?

Sorry, I just realized that I made some mistakes in my original question…

The real code of the Activator is the following:

package com.ruhrboticsGmbH.Profinet.impl;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeService;
import com.ur.urcap.api.contribution.toolbar.swing.SwingToolbarService;

/**
 * Hello world activator for the OSGi bundle URCAPS contribution
 *
 */
public class Activator implements BundleActivator {
	
	@Override
	public void start(BundleContext bundleContext) throws Exception {
	    System.out.println("PROFINET registering!");
	    
	    // ToolbarService registrieren
	    bundleContext.registerService(SwingToolbarService.class, new ToolbarService(), null);
	    
	    // Überprüfen, ob die Registrierung des Services erfolgt
	    SwingToolbarService service = (SwingToolbarService) bundleContext.getService(
	        bundleContext.getServiceReference(SwingToolbarService.class)
	    );
	    if (service != null) {
	        System.out.println("SwingToolbarService successfully registered.");
	    } else {
	        System.out.println("Failed to register SwingToolbarService.");
	    }

	    // Weitere Services registrieren
	    bundleContext.registerService(SwingInstallationNodeService.class, new ProfinetInstallationNodeService(), null);
	}

	@Override
	public void stop(BundleContext context) throws Exception {
		// TODO Auto-generated method stub
		
	}
}

I got an updated output from the terminal:

PROFINET registering!
SwingToolbarService successfully registered.
07:23:21.765 WARN  - Method used before correct value has been received from controller, returning default = joint_max_speed {thread: Thread-4 , loggerClass: com.ur.polyscope.robot.configuration.joint.JointConfigurationSettings}
07:23:21.766 WARN  - Ignoring any future reports of error {thread: Thread-4 , loggerClass: com.ur.polyscope.robot.configuration.joint.JointConfigurationSettings}
Nov 25, 2024 7:23:21 AM com.steadystate.css.parser.CSSOMParser <init>
WARNING: java.lang.ClassNotFoundException: com.steadystate.css.parser.SACParserCSS21 not found by org.w3c.css.sac [170]
Nov 25, 2024 7:23:21 AM com.steadystate.css.parser.CSSOMParser <init>
WARNING: using the default 'SACParserCSS21' instead
07:23:22.302 WARN  - Not connected to controller, trying to send string: 
sec load_installation():
  set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])
  set_safety_mode_transition_hardness(1)
  set_target_payload(0.000000, [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000])
  set_tool_communication(False, 115200, 0, 1, 1.5, 3.5)
  set_tool_output_mode(0)
  set_tool_digital_output_mode(0, 1)
  set_tool_digital_output_mode(1, 1)
  set_tool_voltage(0)
  set_gravity([0.0, 0.0, 9.82])
  set_standard_analog_input_domain(0, 1)
  set_standard_analog_input_domain(1, 1)
  set_tool_analog_input_domain(0, 1)
  set_tool_analog_input_domain(1, 1)
  set_analog_outputdomain(0, 0)
  set_analog_outputdomain(1, 0)
  set_input_actions_to_default()
  step_count_8bbe1bf8_8dbc_4543_99ba_6245c0e97656 = 0.0
  thread Step_Counter_Thread_8bb012b2_d31b_4a96_a28d_434c7f78e7b0():
    while (True):
      step_count_8bbe1bf8_8dbc_4543_99ba_6245c0e97656 = step_count_8bbe1bf8_8dbc_4543_99ba_6245c0e97656 + 1.0
      sync()
    end
  end
  run Step_Counter_Thread_8bb012b2_d31b_4a96_a28d_434c7f78e7b0()
end
 {thread: Thread-4 , loggerClass: com.ur.polyscope.controllerinterface.internal.ControllerSocket}
Creating SwingToolbarContribution...
07:23:28.040 ERROR - No help files found: Help is unavailable! {thread: AWT-EventQueue-0 , loggerClass: com.ur.view.help.HelpLoader}
2024-11-25 07:23:38,156 FATAL Unable to register shutdown hook because JVM is shutting down.
07:23:38.157 WARN  - Incident reporting skipped (too frequent incidents). {thread: AWT-EventQueue-0 , loggerClass: com.ur.polyscope.flightrecorder.internal.FlightRecorderImpl}
07:23:38.215 ERROR - File attachment not found: /home/ur/ursim/ursim-5.11.0.108249/.urcontrol/daemon_ur/log/current {thread: pool-117-thread-1 , loggerClass: com.ur.polyscope.flightrecorder.internal.attachment.FlightRecorderTextFileAttachment}
~/ursim/ursim-5.11.0.108249 ~/ursim/ursim-5.11.0.108249

There you can see the println statements from the activator. But you are right the rest is missing.

So I can’t confirm that the constructor is running properly.
Do you think it might be a good idea to delete the ToolbarService and ToolbarContribution and start from the beginning again? If so, is there a tutorial for the construction of toolbar. For now I just used the toolbar example as a guide.

Yeah I’m still not seeing the other printlns in your terminal output, but if your toolbar is opening that leads me to believe it’s at least running right. It all looks right to me as well. I would say I don’t personally have the revalidate() and repaint() methods in any of my buildUIs, so maybe ditch those?

Hi, wierd situation…
I have the same project twice. One to work and one as backup to always have some runnable code. After I found this failure I took the runable URCap from URSim to have a better overview.
I now installed the runnable URCap on URSim again and now the toolbar works. The code in both projects is the same.
So yeah my problem is kind of solved but I am not able to share a solution.