简体   繁体   English

JFrame 总是稍微偏右

[英]JFrame is always slightly to the right

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.每当我在 JFrame() 上使用 pack() 时,它总是最终稍微偏向屏幕右侧,如您在照片中所见。 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.如果我使用 setLocation(-10, 0) 我可以解决这个问题,但是我不太喜欢这个解决方案,我希望我的应用程序在不同的屏幕分辨率下工作。 Is there any other way to fix this?还有其他方法可以解决这个问题吗? Thanks.谢谢。

Slightly off JFrame:略微关闭 JFrame:

ht H T tps://i.stack.imgur.com/JQ7X0.png

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.我相信这是在 Windows 10 上使用 Swing 时的一个问题。

If I use setLocation(-10, 0)...如果我使用 setLocation(-10, 0)...

That is the standard solution.那是标准的解决方案。

If you want a full screen window than you can use:如果你想要一个全屏 window 比你可以使用:

setExtendedState(JFrame.MAXIMIZED_BOTH);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM