I have to create a Matlab figure window with custom maximize/minimize and close buttons. For it, I use a JWindow window. I have had to add a JPanel to it because this is the only way with I can get to change its background color (I do not understand why this happens). Now, I want to add Matlab uipanels components. However, when I try to do it, I get the following errors:
??? Error using ==> uipanel
An object of class uipanel, can not be a child of class javax.swing.JPanel.
Here is my code:
import javax.swing.*;
import java.awt.*;
jW = JWindow;
jW.setAlwaysOnTop(true);
jW.setSize(200,200);
jW.setLocation(0,0);
panel = javaObjectEDT('javax.swing.JPanel');
panel.setBackground(java.awt.Color.black);
jW.getContentPane().add(panel);
ph = uipanel('Parent',panel,'Units','pixels','Position',[0 0 100 100]);
jW.setVisible(true);
I do not know how to fix this.
You cannot add a uipanel to a JPanel or any other Java container. A better approach, albeit still hacky, would be to get a handle to the figure window’s JFrame and change the buttons there.