Removing a panel without affecting buttons and axis

18 views (last 30 days)
I'm making a game with a group and it currently plays well but looks horrendous, i'm trying to neaten it up and make it look better by adding a background image, however the guy who made the code has a panel behind all the axis and buttons. How can I remove this without affecting the axis and buttons, or is there a way to make it transparent?
Thanks

Answers (2)

Yair Altman
Yair Altman on 10 Jan 2018
Here is an undocumented way to set the panel's background to transparent - this works on HG2 (R2014b onward):
jPanel = hPanel.JavaFrame.getPrintableComponent; % hPanel is the Matlab handle to the uipanel
jPanel.setOpaque(0);
jPanel.getComponent(0).setOpaque(0);
jPanel.getParent.setOpaque(0);
jPanel.repaint
In HG1 (R2014a or earlier) you can simply set the hPanel's BackgroundColor to 'none'
Yair Altman
  3 Comments
Walter Roberson
Walter Roberson on 24 Apr 2018

It works for me, showing whatever is underneath.

>> imshow('cameraman.tif')
>> hPanel = uipanel('units','norm','position',[0 0 .5 .5])
hPanel = 
  Panel with properties:
                Title: ''
      BackgroundColor: [0.94 0.94 0.94]
             Position: [0 0 0.5 0.5]
                Units: 'normalized'
    Show all properties
  >> jPanel = hPanel.JavaFrame.getPrintableComponent;  % hPanel is the Matlab handle to the uipanel
  jPanel.setOpaque(0);
  jPanel.getComponent(0).setOpaque(0);
  jPanel.getParent.setOpaque(0);
  jPanel.repaint
Jonas
Jonas on 8 May 2023
in 2022a the JavaFrame returns an empty object. how to do this in 2022a?

Sign in to comment.


Walter Roberson
Walter Roberson on 20 Dec 2017
The uipanel can be set to 'Color', 'none' to make it transparent.
It is often very convenient to use a uipanel to position buttons and axes properly, so removing the uipanel would not be my first choice.
  3 Comments
Walter Roberson
Walter Roberson on 6 Jan 2018
You appear to be correct on both points.
Also, as is the undocumented case with several of the HG2 color, you can set the BackGround color to a 4 element vector instead of a 3 element vector. In some controls, the 4th element is alpha value. However for uipanel the 4th element is accepted but has no effect.
The implementation appears to involve a java frame of class com.mathworks.hg.peer.ui.UIPanelPeer which does not appear to support alpha values. Or rather, you can set the alpha component and it will remember it if you know how to ask for it, but it does not appear to use the alpha.
Yair Altman
Yair Altman on 10 Jan 2018
In HG1 (up to R2014a) you could set BackgroundColor to 'none'; in HG2 (R2014b or newer) this is no longer possible and you have to use the underlying Java component. See my answer for details.

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!