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

2 次查看(过去 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