Swing GUI 間歇性空白,這里是一張圖片,顯示我循環(huán)執(zhí)行代碼以顯示 GUI 5 次,最后一次是空白的我正在使用 InvokeLater 執(zhí)行 GUI,我試過沒有它,結(jié)果還是一樣。這是足夠的代碼來啟動和運行 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); } }); }}這應(yīng)該足以重現(xiàn)錯誤。
2 回答

白衣染霜花
TA貢獻1796條經(jīng)驗 獲得超10個贊
好吧,看起來沒有人想回答這個問題,所以我會繼續(xù)讓你們知道是什么解決了這個問題。我setVisible
在添加所有視圖的最后打電話,感謝@Madprogrammer
添加回答
舉報
0/150
提交
取消