Home > Blockchain >  SWT check if shell exceeds screen bounds
SWT check if shell exceeds screen bounds

Time:05-02

I have a button that opens a shell in my application, which displays a number of checkboxes, along with 2 buttons at the bottom. The problem is that it can get cut off due to its height being too big.

The solution I want is to add the contents of the shell to a ScrollableComposite, which doesn't work, because the shell just expands in height, so the composite's scrollbars don't do anything.

I figured the best way would be to calculate if the shell exceeds the screen bounds, but I don't understand how its coordinates really work. The shell's parent is a shell, so Shell::getBounds() is supposed to return the coordinates relative to the display, but I think I need the shell's bounds relative to the monitor (which I can get through Shell::getMonitor()) in this case.

How can I do this ?

CodePudding user response:

Just set the shell size based on the monitor size rather than the bounds.

This is what the Eclipse Launch Configuration Dialog uses to make sure it is not too big:

protected void setShellSize(int width, int height) {
    Rectangle bounds = getShell().getMonitor().getBounds();
    getShell().setSize(Math.min(width, bounds.width), Math.min(height, bounds.height));
}
  • Related