2011-08-18 54 views
1

如何使重繪了的JDialog在Swing? 如果我的JDialog點擊轉換按鈕我需要改變的JDialog的GUI設計,但它沒有發生?他們的任何解決方案?如何在Swing中重繪JDialog?

_convertAction = new AbstractAction() { 
     public void actionPerformed(ActionEvent e) { 
      String para = new String(); 
      _task.setBookTypeId(13); 
      initComponents(); 
      // validate(); 
      // repaint(); 
      setVisible(true); 
     } 
     }; 

我在設置預約類型ID爲13。

if(_task.getBookTypeId()== 1){ 
    String colnames[] = {"Leg","Departure", "Date","Time", "Arrival","Date", "Time","How","Aircraft","PIC","Copilot"}; 
    MyTableModel mytablemodel = new MyTableModel(colnames); 
    legdetailsTable = new JTable(mytablemodel); 
    legdetailsTable.setRowSelectionAllowed(true); 
}else { 
    System.out.println("Brokered booking table"); 
    String colnames[] = {"Leg","Departure", "Date","Time", "Arrival","Date", "Time","How"}; 
    MyTableModel mytablemodel = new MyTableModel(colnames); 
    legdetailsTable = new JTable(mytablemodel); 
    legdetailsTable.setRowSelectionAllowed(true); 
} 

使用Id我正在更改initcomponents方法中的組件。

+0

@Jonas如果OP員額[SSCCE] (http://pscode.org/sscce.html),它保證了相關代碼的存在。但是,直到他們解決問題,大多數人*沒有使用重繪,但不知道工作相關的代碼是什麼。* –

回答

2

您可以獲得當前組件或任何組件的窗口,比打電話repaint()。取而代之的

legdetailsTable = new JTable(mytablemodel); 

SwingUtilities.getWindowAncestor(this).repaint(); 
+0

IM – Ganesh

3

添加

legdetailsTable.setModel(mytablemodel); 

您重新JTable中,但新一不添加到佈局