Removing a panel without affecting buttons and axis

조회 수: 15 (최근 30일)
Matthew Maher
Matthew Maher 2017년 12월 20일
댓글: Jonas 2023년 5월 8일
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

답변 (2개)

Yair Altman
Yair Altman 2018년 1월 10일
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
Walter Roberson
Walter Roberson 2018년 4월 24일

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 2023년 5월 8일
in 2022a the JavaFrame returns an empty object. how to do this in 2022a?

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2017년 12월 20일
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
Walter Roberson
Walter Roberson 2018년 1월 6일
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 2018년 1월 10일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by