Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to resize a java component within a uipanel if its figure is docked?

Subject: How to resize a java component within a uipanel if its figure is docked?

From: Lihua Pan

Date: 9 Jan, 2009 16:41:02

Message: 1 of 3

I've constructed a uipanel within a figure and then I want to create some java swing component within the uipanel, such as JPanel, using the function "javacomponent". The problem is, if I set the figure docked, the width and height of uipanel from "Position" property are no longer the original one. I have to set the JPanel size adapt to the uipanel (the size of uipanel will adapt to the figure automatically). and also if the user resizes the uipanel(figure) when the figure has been undocked.
There are some code examples written by me, but it runs not correctly.
Thank you in advance!
------------------------------------------------------
hMainFigure = figure('WindowStyle','docked',...
                     'Menubar','none',...
                     'DockControls','on',...
                     'NumberTitle','off',...
                     'Units','pixels');

posFigure = get(hMainFigure,'Position');

hUipanel = uipanel('Parent',hMainFigure,'Units','normalized');
set(hUipanel,'Position',[0, 0, posFigure(3),posFigure(4)]);
posUipanel = get(hUipanel, 'Position');
...

hMainPanel = JPanel();
...

javacomponent(hMainPanel,[0,0,posUipanel(3),posUipanel(4)],hUipanel);


% Set the resize callback function of uipanel container
set(hUipanel,'ResizeFcn',{@UipanelResizeCallback,hUipanel,hMainPanel});

...

%% Callback function for resize behavior of the uipanel container
function UipanelResizeCallback(hObject, eventdata, handles, hMainPanel, varargin)

import javax.swing.*;
import java.awt.*;

posUipanel = get(handles, 'Position');
    
if ~isempty(hMainPanel)
    hMainPanel.setSize(Dimension(posUipanel(3),posUipanel(4)));
end

Subject: How to resize a java component within a uipanel if its figure is docked?

From: Yair Altman

Date: 14 Feb, 2009 21:05:05

Message: 2 of 3

"Lihua Pan" <plhalice@gmx.de> wrote in message...
> I've constructed a uipanel within a figure and then I want to create some java
> swing component within the uipanel, such as JPanel, using the function
> "javacomponent". The problem is, if I set the figure docked, the width and height of
> uipanel from "Position" property are no longer the original one. I have to set the
> JPanel size adapt to the uipanel (the size of uipanel will adapt to the figure
> automatically). and also if the user resizes the uipanel(figure) when the figure has
> been undocked.
> ...
> javacomponent(hMainPanel,[0,0,posUipanel(3),posUipanel(4)],hUipanel);

javacomponent() returns 2 handles: a handle to the java component and another handle to its Matlab container. Simply set the container's units to 'normalized' after using javacomponent().

You may also find interest in my related UICOMPONENT function, submitted on the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/14583

Yair Altman

Subject: How to resize a java component within a uipanel if its figure is docked?

From: Shahar

Date: 9 Oct, 2012 15:09:08

Message: 3 of 3

[a, hparent] = actxcontrol(...);
set(hparent, 'Units', 'normalized');

Really does the trick! Thanks for the answer!

Shahar

> javacomponent() returns 2 handles: a handle to the java component and another handle to its Matlab container. Simply set the container's units to 'normalized' after using javacomponent().
>
> You may also find interest in my related UICOMPONENT function, submitted on the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/14583
>
> Yair Altman

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us