JFrame 总是稍微偏右

JFrame is always slightly to the right

您好,我正在制作一个日志记录应用程序。每当我在 JFrame() 上使用 pack() 时,它总是最终稍微偏向屏幕右侧,如您在照片中所见。如果我使用 setLocation(-10, 0) 我可以解决这个问题,但是我不太喜欢这个解决方案,我希望我的应用程序在不同的屏幕分辨率下工作。还有其他方法可以解决这个问题吗?谢谢

JFrame 略有偏差:

ht

最小可重现示例:

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

我认为这是在 Windows 10 上使用 Swing 时的一个问题。

If I use setLocation(-10, 0)...

这是标准的解决方案。

如果你想要全屏 window 你可以使用:

setExtendedState(JFrame.MAXIMIZED_BOTH);