如何摆脱Jframe底部和右侧的白色1PX线?
我想要一个jpanel
,该目前是黑色的,但会在jframe
内更改颜色。我只设置了面板的大小,然后在我的框架上调用.pack
,但是我框架的底部和右侧出现了一条丑陋的白色1PX线。为什么那是这样,我该如何修复? 我目前正在运行Windows 11。
import javax.swing.JFrame;
public class Main {
private static GamePanel gamePanel;
public static void main(String[] args) {
createWindow();
gamePanel = new GamePanel();
window.add(gamePanel);
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);
}
private static JFrame window;
private static void createWindow() {
window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setTitle("My Game");
window.setResizable(false);
}
}
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JPanel;
public class GamePanel extends JPanel {
// Screen settings
final int originalTileSize = 16;
final int scaleFactor = 3;
final int tileSize = originalTileSize * scaleFactor;
final int maxScreenCol = 16;
final int maxScreenRow = 12;
final int screenWidth = maxScreenCol * tileSize;
final int screenHeight = maxScreenRow * tileSize;
// --- Constructor ---
GamePanel () {
this.setPreferredSize(new Dimension(screenWidth, screenHeight));
this.setBackground(Color.black);
this.setDoubleBuffered(true);
}
public int getScreenWidth () {
return screenWidth;
}
}
I want a JPanel
which is currently black but will change color, inside of a JFrame
. I only set the size of the panel and then call .pack
on my frame, but an ugly white 1px line appears on the bottom and right side of my frame. Why is that and how can I fix it?
I am currently running Windows 11.
import javax.swing.JFrame;
public class Main {
private static GamePanel gamePanel;
public static void main(String[] args) {
createWindow();
gamePanel = new GamePanel();
window.add(gamePanel);
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);
}
private static JFrame window;
private static void createWindow() {
window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setTitle("My Game");
window.setResizable(false);
}
}
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JPanel;
public class GamePanel extends JPanel {
// Screen settings
final int originalTileSize = 16;
final int scaleFactor = 3;
final int tileSize = originalTileSize * scaleFactor;
final int maxScreenCol = 16;
final int maxScreenRow = 12;
final int screenWidth = maxScreenCol * tileSize;
final int screenHeight = maxScreenRow * tileSize;
// --- Constructor ---
GamePanel () {
this.setPreferredSize(new Dimension(screenWidth, screenHeight));
this.setBackground(Color.black);
this.setDoubleBuffered(true);
}
public int getScreenWidth () {
return screenWidth;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论