Finding the height of windows taskbar

30 views (last 30 days)
IISc geetha
IISc geetha on 21 Nov 2012
Answered: Jan on 24 Mar 2021
Dear all, I want to place my figure above the location of the taskbar. The height of the taskbar varies according to screen size..Can somebody tell me how to find the height of the windows taskbar in pixels using Matlab.
Yours faithfully, Geetha

Answers (3)

Ralph Coleman
Ralph Coleman on 7 Oct 2020
Edited: Ralph Coleman on 7 Oct 2020
Temporarily maximizing a window is slow, and the Position property is not updated until rendering has completed.
Fortunately, if you do not mind using Java commands in your MATLAB script, there is a much more elegant way to find the screen size and the space occupied by the taskbar of your main display:
toolkit = java.awt.Toolkit.getDefaultToolkit();
scr_size = toolkit.getScreenSize();
fprintf('Screen size is: %d x %d\n', scr_size.width, scr_size.height)
jframe = javax.swing.JFrame;
insets = toolkit.getScreenInsets(jframe.getGraphicsConfiguration());
fprintf('Windows task bar height is: %d\n', insets.bottom)
Note that the other properties of "insets" can be used if the taskbar is not located in the usual place at the bottom.
scr_size = get(0,'ScreenSize');
titleBarHeight = 31;
scr_size = scr_size + ...
[insets.left, insets.bottom, -insets.left-insets.right,];
uifigure('Position', scr_size);
This example code will create a figure which fills the available space (without being maximized), independently of the position of the taskbar.
To avoid hard-coding the height of the title bar (31 pixels), you could use the following code, but there must exist a better way I am sure to retrieve this value, which does not depend on MATLAB but on the operating system.
fh = figure('Menu','none','ToolBar','none','Visible','off');
titleBarHeight = fh.OuterPosition(4) - fh.InnerPosition(4) + fh.OuterPosition(2) - fh.InnerPosition(2);

Matt Fig
Matt Fig on 21 Nov 2012
Here is how to figure it out. First make a figure then maximize it, then look at its position.
>> figure % maximize this figure
>> P2 = get(gcf,'pos');
>> P2(2) % The taskbar height.
ans =
Daniel Charles
Daniel Charles on 1 May 2019
I like your idea of maximing a figure to find the usable area of the screen. Perhaps a more complete approach would look something like this:
h = figure('Units','pixels'); % open a figure, save the handles to a variable
h.WindowState = 'maximized'; % maximize the figure window
h.OuterPosition % will give you [x-location, y-location, width, height] relative to the lower lefthand corner of the screen
You can get the position(s) and size(s) of the monitor(s) using:
r = groot; % graphics root object
r.MonitorPositions % will give you [x-location, y-location, width, height] for each monitor in rows
Then you can do the math to figure out which screen the figure is on, if the taskbar is on that screen, and, if so, where.

Sign in to comment.

Jan on 24 Mar 2021
You can move the taskbar to the side and to the top, hide it dynamically and change the size. The static determination of the height is not reliable.
You can use FEX: WindowAPI to determine the sizes of the monitors with and without task bar.

Community Treasure Hunt

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

Start Hunting!

Translated by