How can I force a figure window to open behind another on a monitor that is not the default?

조회 수: 4 (최근 30일)
I am working on a program that uses one main figure, but upon closing all of the tabs, a new instance of that object is created and replaces the old one. When working with multiple monitors, I tend to open the main object and move it to my secondary monitor, but when the replacement object opens, it is on the primary monitor. I want it to be in the exact location as the old object though. I also experience a similar problem when using the waitbar tool, and I want those figures to open in the center of my current figure as opposed to on the main monitor.
This is my current attempt:
wait = waitbar(0, 'Closing Tab...')
curr_fig = gcf; % For This object
pos = get(curr_fig,'Position');
waitbar(.2, wait);
obj = MyObj(); % Creates the new object and opens the figure
new_fig = gcf;
new_pos = get(new_fig, 'Position');
waitbar(.4, wait);
new_pos(1) = pos(1); new_pos(2) = pos(2); % Prevents resizing the new object window smaller
set(new_fig,'Position', new_pos, 'Visible', 'off');
waitbar(.6, wait);
% Does some things here
waitbar(.8, wait);
delete(this);
waitbar(1, wait);
delete(wait);
set(new_fig,'Visible', 'on');
...
Unfortunately, the new object still shows up on the primary monitor opposed to the monitor with the original figure.
  댓글 수: 3

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

답변 (1개)

Jatin Waghela
Jatin Waghela 2017년 6월 23일
Could be that the first gcf call is getting the position of the waitbar, not the original object? Or it was getting the position before he moved it over to the second monitor. Debugging step by step and ensuring that the figure handle and the position values are as expected would probably help here.

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by