Automatically set screen size according to monitor size using swing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PreethiGowri
    New Member
    • Oct 2012
    • 126

    Automatically set screen size according to monitor size using swing

    I have created a desktop application using java swing on a system with resolution- 1920 x 1080. When i run this application on a lower resolution screen the screen size seems to be to large to be visible on the lower screen resolution sizes. How do i overcome this problem using programming?

    I have tried below code, which is not satisfying
    Code:
    Toolkit t = Toolkit.getDefaultToolkit();
            Dimension d = t.getScreenSize();
            int h = d.height;
            int w = d.width;
            this.setSize( 1200 , 950 );

    Any other options please..
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    You set the size to 1200x950 no matter what? Shouldn't that be
    Code:
    this.setSize(w, h);
    then?

    Also, what exactly is what you want it to do? Go fullscreen? If so, maybe
    Code:
    this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    will be the easiest solution.

    Comment

    • PreethiGowri
      New Member
      • Oct 2012
      • 126

      #3
      i shall try this and get back to you.

      Comment

      • Dikaios
        New Member
        • Jun 2016
        • 1

        #4
        Try this...
        Select all components of JFrame, right click, select 'Auto Resizing', check for both Horizontal and Vertical, close .

        Comment

        Working...