Hi so I am making a logging application. Whenever I use pack() on JFrame() it always ends up being slightly to the right of my screen as you can see in the photo. If I use setLocation(-10, 0) I can fix this however, I don't really like this solution and I want my application to work on different screen resolutions. Is there any other way to fix this? Thanks.
Slightly off JFrame:
Minimum reproducible example:
public class LogMonitor extends JFrame {
public LogMonitor() {
setTitle("Log Monitor");
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension newDi = new Dimension((int) Math.round(screenSize.width), (int) Math.round(screenSize.height*0.80));
//setSize((int) Math.round(screenSize.width), (int) Math.round(screenSize.height*0.80));
overallPanelSetup();
createFilterSection();
createLogTable("ALL", "20");
add(overallPanel);
pack();
setVisible(true);
revalidate();
repaint();
}
}
it always ends up being slightly to the right of my screen
I believe this is an issue when using Swing on Windows 10.
If I use setLocation(-10, 0)...
That is the standard solution.
If you want a full screen window than you can use:
setExtendedState(JFrame.MAXIMIZED_BOTH);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.