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

4 views (last 30 days)
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 Comments

Sign in to comment.

Answers (1)

Jatin Waghela
Jatin Waghela on 23 Jun 2017
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.

Categories

Find more on Dialog Boxes in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!