Removing a panel without affecting buttons and axis

15 vues (au cours des 30 derniers jours)
Matthew Maher
Matthew Maher le 20 Déc 2017
Commenté : Jonas le 8 Mai 2023
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

Réponses (2)

Yair Altman
Yair Altman le 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 commentaires
Walter Roberson
Walter Roberson le 24 Avr 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 le 8 Mai 2023
in 2022a the JavaFrame returns an empty object. how to do this in 2022a?

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 20 Déc 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 commentaires
Walter Roberson
Walter Roberson le 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 le 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by