Swing GUI 间歇性空白,这里是一张图片,显示我循环执行代码以显示 GUI 5 次,最后一次是空白的我正在使用 InvokeLater 执行 GUI,我试过没有它,结果还是一样。这是足够的代码来启动和运行 GUI public class Main_UI extends JFrame { public Main_UI() { JPanel gui = new JPanel(new BorderLayout()); setUndecorated(true); setLocationRelativeTo(null); setVisible(true); setSize(329, 256); setResizable(false); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ThemeUtils.setTopBar(gui, this); }}这是代码 ThemeUtils.setTopBar public static void setTopBar(JPanel jPanel, JFrame frame) { JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JButton exitButton = new JButton("X"); JButton minimizeButton = new JButton("-"); topPanel.add(minimizeButton); topPanel.add(exitButton); jPanel.add(BorderLayout.NORTH, topPanel); new DragFeatures(topPanel, frame).setupDragFeatures();}最后是DragFeatures课程代码public class DragFeatures { private Point compCoords; private JPanel panel; private JFrame frame; public DragFeatures(JPanel panel, JFrame frame) { this.panel = panel; this.frame = frame; } public void setupDragFeatures() { compCoords = null; panel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { compCoords = null; } public void mousePressed(MouseEvent e) { compCoords = e.getPoint(); } }); panel.addMouseMotionListener(new MouseMotionListener() { public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { Point currCoords = e.getLocationOnScreen(); frame.setLocation(currCoords.x - compCoords.x, currCoords.y - compCoords.y); } }); }}这应该足以重现错误。
2 回答
白衣染霜花
TA贡献1796条经验 获得超10个赞
好吧,看起来没有人想回答这个问题,所以我会继续让你们知道是什么解决了这个问题。我setVisible
在添加所有视图的最后打电话,感谢@Madprogrammer
添加回答
举报
0/150
提交
取消