In this website, I have often shown how Matlab application functionality can be significantly enhanced by including Java components in the Matlab GUI, using the built-in semi-documented javacomponent function (which I described here last year).
Using java components in Matlab is simple and easy, but there are a few annoying catches. One of these is the fact that the default Matlab figure background color ([0.8, 0.8, 0.8]) is a different shade of gray than the default uicontrol background color ([0.9255, 0.9137, 0.847]). javacomponents use the same background color as uicontrols.
hPanel = uipanel('units','pixe', 'pos',[30,30,200,100], 'title','Matlab uipanel'); jLabel = javax.swing.JLabel('Java Label'); [jhlabel,jContainer]=javacomponent(jLabel, [250,50,100,50], gcf);

Javacomponents use different default background color than figures
While Matlab users are familiar with updating Matlab colors, doing so with Java colors is a bit different. We have two basic ways to align the javacomponent background color with the figure’s: either change the figure’s Color property to the Java component’s bgcolor, or vice versa:
Changing the javacomponent‘s background color to the figure color
% Fix the Java component: % Variant #1 bgcolor = get(gcf, 'Color'); jLabel.setBackground(java.awt.Color(bgcolor(1),bgcolor(2),bgcolor(3))); % Variant #2 bgcolor = num2cell(get(gcf, 'Color')); jLabel.setBackground(java.awt.Color(bgcolor{:})); % Fix the Matlab panel uicontrol set(hPanel, 'BackgroundColor', get(gcf,'Color'));

controls with fixed background colors
Changing the figure’s color to the javacomponent‘s background color
bgcolor = jLabel.getBackground.getComponents([]); set(gcf, 'Color', bgcolor(1:3));

figure with modified color to match the controls
Look at the list of related posts below for other articles related to colors in Matlab.
Related posts:
- Common javacomponent problems The javacomponent function is very useful for placing Java components on-screen, but has a few quirks. ...
- The javacomponent function Matlab's built-in javacomponent function can be used to display Java components in Matlab application - this article details its usages and limitations...
- Color selection components Matlab has several internal color-selection components that can easily be integrated in Matlab GUI...
- cprintf – display formatted color text in the Command Window cprintf is a utility that utilized undocumented Matlab desktop functionalities to display color and underline-styled formatted text in the Command Window...
- Customizing figure toolbar background Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...
- Bold color text in the Command Window Matlab Command Window text can be formatted *bold* since R2011b. ...



hello,
(How) is it possible to place the panel label(name) someplace else than the top of it?
thanks in advance
@Panos – you can easily get the handle of the panel label and then modify its Position property, as well as other aspects: color, font, and even component style, as described here: http://UndocumentedMatlab.com/blog/panel-level-uicontrols/