I am writing a program where I have a varying sized JFrame. If the content in the JFrame is larger than the screen size, I am providing scrolling.
Now I have the situation where the user could have two (or more) screens with different resolutions. What I am wanting to accomplish is to write a listener that does the following:
1) Notices when the JFrame has been moved
2) When the moving stops, Determine which screen the JFrame is being displayed on
3) Resize the JFrame appropriately for the screen's resolution
I currently have a check in place for it displaying on the default screen when the JFrame opens. Here is the code I have for that in case anyone is interested:
JFrame puzzleFrame = new JFrame("Hashi Puzzle"); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); puzzleFrame.setMaximumSize(dim); puzzleFrame.setSize((iconSize*puzzleSize)+50,(iconSize*puzzleSize)+50); if(dim.getWidth()<=puzzleFrame.getWidth() && dim.getHeight()<=puzzleFrame.getHeight()) { puzzleFrame.setMaximizedBounds(new Rectangle(dim)); puzzleFrame.setExtendedState(puzzleFrame.getExtendedState()|JFrame.MAXIMIZED_BOTH); } else { if(dim.getWidth()<=puzzleFrame.getWidth()) puzzleFrame.setSize((int)dim.getWidth()-50,puzzleFrame.getHeight()); if(dim.getHeight()<=puzzleFrame.getHeight()) puzzleFrame.setSize(puzzleFrame.getWidth(),(int)dim.getHeight()-50); }
I'm wanting to do the same basic thing, but with a listener for when the JFrame moves instead of just when the JFrame opens. Any help is appreciated.