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 Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by