Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:01:48+00:00 2026-06-14T07:01:48+00:00

This question discusses a known bug where JFrames extend into the windows taskbar. An

  • 0

This question discusses a known bug where JFrames extend into the windows taskbar. An answer links to the bug report (which has various duplicates) and provides a workaround. I’ve discovered that the problem also holds for JDialogs. The JFrame workaround does not apply. Is there a similar workaround to make JDialogs behave themselves on windows?

Example code:

import javax.swing.*;

public class Demo extends JDialog {
    public Demo() {
        setSize(250,12500);
        setVisible(true);
    }
    public static void main(String[] args) {
        new Demo();
    }
}

Edit:
It looks like this will not be fixed in the JDK. This bug report closes with the comment that “If a developer wants to keep their windows entirely visible on the screen, they should consider checking the screen insets themselves [like the solution below], and re-layout their component in a different way, or re-size the window manually after calling pack(), or use a screen-insets-aware layout manager [unlike more common ones like BorderLayout and GridBagLayout].”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:01:50+00:00Added an answer on June 14, 2026 at 7:01 am

    This will basically make sure that the dialog “fits” into the specified screen by moving it to be within the bounds of the specified device and shrinking it so that it’s left and bottom edges are within the bounds of the specified device.

    This looks at the devices bounds and insets to calculate the “safe” area that the dialog can reside.

    public class TestScreenSize {
    
        public static void main(String[] args) {
            new TestScreenSize();
        }
    
        public TestScreenSize() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException ex) {
                    } catch (InstantiationException ex) {
                    } catch (IllegalAccessException ex) {
                    } catch (UnsupportedLookAndFeelException ex) {
                    }
    
                    Test test = new Test();
                    test.setLayout(new BorderLayout());
                    test.setVisible(true);
                    System.exit(0);
                }
            });
        }
    
        public class Test extends JDialog {
    
            public Test() {
                setModal(true);
                setLocation(0, 0);
                setSize(2000, 2000);
            }
    
            @Override
            public void setBounds(int x, int y, int width, int height) {
                Rectangle bounds = getSafeScreenBounds(new Point(x, y));
                if (x < bounds.x) {
                    x = bounds.x;
                }
                if (y < bounds.y) {
                    y = bounds.y;
                }
                if (width > bounds.width) {
                    width = (bounds.x + bounds.width) - x;
                }
                if (height > bounds.height) {
                    height = (bounds.y + bounds.height) - y;
                }
                super.setBounds(x, y, width, height);
            }
    
        }
    
        public static Rectangle getSafeScreenBounds(Point pos) {
    
            Rectangle bounds = getScreenBoundsAt(pos);
            Insets insets = getScreenInsetsAt(pos);
    
            bounds.x += insets.left;
            bounds.y += insets.top;
            bounds.width -= (insets.left + insets.right);
            bounds.height -= (insets.top + insets.bottom);
    
            return bounds;
    
        }
    
        public static Insets getScreenInsetsAt(Point pos) {
            GraphicsDevice gd = getGraphicsDeviceAt(pos);
            Insets insets = null;
            if (gd != null) {
                insets = Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration());
            }
            return insets;
        }
    
        public static Rectangle getScreenBoundsAt(Point pos) {
            GraphicsDevice gd = getGraphicsDeviceAt(pos);
            Rectangle bounds = null;
            if (gd != null) {
                bounds = gd.getDefaultConfiguration().getBounds();
            }
            return bounds;
        }
    
        public static GraphicsDevice getGraphicsDeviceAt(Point pos) {
    
            GraphicsDevice device = null;
    
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice lstGDs[] = ge.getScreenDevices();
    
            ArrayList<GraphicsDevice> lstDevices = new ArrayList<GraphicsDevice>(lstGDs.length);
    
            for (GraphicsDevice gd : lstGDs) {
    
                GraphicsConfiguration gc = gd.getDefaultConfiguration();
                Rectangle screenBounds = gc.getBounds();
    
                if (screenBounds.contains(pos)) {
    
                    lstDevices.add(gd);
    
                }
    
            }
    
            if (lstDevices.size() > 0) {
                device = lstDevices.get(0);
            } else {
                device = ge.getDefaultScreenDevice();
            }
    
            return device;
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually this question is based on a Blog Entry , which discusses the topic
I know this question has been discussed before, and I know this is such
This question has no practical issues associated with it, it is more a matter
I know this is a question that has been discussed over and over, but
This question I have asked before and just got answer that there is an
I have a question which I see from googling has been discussed at length..
I know this question has been discussed before, but i am interested in doing
First of all, I am aware that this question has been discussed many times
This question discusses how to create gaps between views in a UIScrollView. The agreed
I DO know this question has been asked at least a thousand times in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.