Forum Stats

  • 3,851,490 Users
  • 2,263,988 Discussions


AWT GUI frames differ widely in size between PC screen sizes

Java Neophyte
Java Neophyte Member Posts: 7
edited Jan 10, 2019 7:23PM in Abstract Window Toolkit (AWT)

I just finished a Java AWT class at the local college where the professor stayed away from the GUI frame layout code. As a student I went with his assignments and didn't give this another thought. I then wrote a small app that uses Java GUI and it works great on one PC (24" screen)  but on a smaller screened PC (14")  the frames are very small, too small. I thought that defining GUI frames and their components in pixels would take care of this but apparently not. Here is a small snippet of a frame def:

// FRAME components


  this.setSize(800,400);                   // <-- Frame size





Is there a straightforward way to port apps over to other PC's whose screens are much smaller (24" down to 14") and have the frames compensate for the difference in screen size? The smaller screen's frames are way to small to be useful.

Many thanks from a newbie...


  • morgalr
    morgalr Member Posts: 457
    edited Jan 10, 2019 7:23PM

    In the Toolkit API there is a call, getScreenResolution, which returns an integer value representing the dots per inch of your monitor; this may be applicable to your needs.

    please note: Toolkit tk=Toolkit.getDefaultToolkit() with get the specifics of the Toolkit object in effect during your session.