2013-03-15 21 views
0

我在一個swing應用程序上工作,一切似乎都工作得很好,但最近我遇到了GUI的一些問題。 問題是,當我打開一個JinternalFrame裏面另一個它工作正常,但是當我再次打開它的孩子JintenalFrame失去控制自己,佈局丟失或者可能被破壞我有一些照片,將清楚地解釋問題:如何解決Swing GUI錯誤?

enter image description here

這是第一個JInternalFrame的,當我在更新按鈕點擊第二個顯示出來它裏面想:

enter image description here

但是當我關閉Seconde系列之一,開放它再次出現E題這樣的: enter image description here

而且IDE觸發NPE提的是:

Hibernate: select modalite0_.id_mod as id1_6_, modalite0_.libele as libele6_ from 
Modalite modalite0_ 
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException 
at javax.swing.JTable.prepareRenderer(JTable.java:5735) 
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2114) 
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:2016) 
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1812) 
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161) 
at javax.swing.JComponent.paintComponent(JComponent.java:778) 
at javax.swing.JComponent.paint(JComponent.java:1054) 
at javax.swing.JComponent.paintChildren(JComponent.java:887) 
at javax.swing.JComponent.paint(JComponent.java:1063) 
at javax.swing.JViewport.paint(JViewport.java:731) 
at javax.swing.JComponent.paintChildren(JComponent.java:887) 
at javax.swing.JComponent.paint(JComponent.java:1063) 
at javax.swing.JComponent.paintChildren(JComponent.java:887) 
at javax.swing.JComponent.paint(JComponent.java:1063) 
at javax.swing.JComponent.paintChildren(JComponent.java:887) 
at javax.swing.JComponent.paint(JComponent.java:1063) 
at javax.swing.JComponent.paintChildren(JComponent.java:887) 
at javax.swing.JComponent.paint(JComponent.java:1063) 
at javax.swing.JLayeredPane.paint(JLayeredPane.java:585) 
at javax.swing.JComponent.paintChildren(JComponent.java:887) 
at javax.swing.JComponent.paint(JComponent.java:1063) 
at javax.swing.JComponent.paintChildren(JComponent.java:887) 
at javax.swing.JComponent.paint(JComponent.java:1063) 
at javax.swing.JComponent.paintChildren(JComponent.java:887) 
at javax.swing.JComponent.paint(JComponent.java:1063) 
at javax.swing.JLayeredPane.paint(JLayeredPane.java:585) 
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221) 

所以我詢問是否有一種方法來跟蹤這個錯誤了嗎?

我使用Netbeans7.2作爲IDE與JRE 7。

+0

PLZ粘貼你的幀間代碼。我想看看你如何創建jinternalframe – Biswajit 2013-03-15 11:52:03

+1

這樣的東西通常更新事件調度線程(EDT)之外的GUI。基本上,如果您在Swing的專用EDT以外的任何線程中進行更新,則無法保證它能正常工作。你的代碼是否包含任何其他線程? – Ash 2013-03-15 11:53:02

+0

請顯示代碼,但您是否設置了DISPOSE_ON_CLOSE選項? – 2013-03-15 11:55:25

回答

3

@Zakaria Marrah

  • 的彈出窗口創建JDialog,只有一個JDialog爲整個JVM實例,通過假定在某一時刻可以看到只有一個彈出窗口,設置適當的JDialog.setDefaultCloseOperations(HIDE_ON_CLOSE)

  • 創建JPanel嵌套全部JComponents

  • add/intialize XxxTableModel to JTable,錯誤編碼渲染器和空模型從prepareRenderer造成exceptions所有harcoded鏈接,鑄件,價值comparitions,則有測試是否模型,如果通過則允許任何渲染器的工作原理

  • 錯編碼renderer裏面包含prepareRenderer數據並連同更新出來的EDT從prepareRenderer導致異常的所有harcoded鏈接,鑄件,價值comparitions,


  • 現在你只visibily玩JDialog及其內容

  • 隱藏JDialog

  • 使用CardLayout中,有一些看法,設置,切換到適當的卡,

  • 的情況下
  • 移除JComponent(多個)的所有值,或從model(多個)中刪除所有的數據,

  • 從不復位,重新初始化或者重新創建任何對象上,

  • 使用SwingWorker用於從任何外部souces數據,通過使用PropertyChangeListener聽,have to test, to check for exceptions by using get() in done()

  • 設定值(或者通過在process使用分批,publish)在done()JComponent S,其model小號

  • 然後致電JDialog.pack(),與JDialog一起移動到屏幕上的相應座標(相對於JComponents),移動到Point,然後顯示JDialog裹在invokeLater(required)


  • 生產代碼中使用Runnable#Thread,但所有的輸出到了Swing GUI必須被包裹成invokeLater,你可以忽略一些方法聲明爲Swing as thread safe