如何在Swing中为JDialog进行重绘?
如果我在JDialog中单击转换按钮,我需要更改JDialog的GUI设计,但是没有发生吗?他们有什么解决方案吗?
_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方法中更改组件。
最佳答案
您可以获取当前组件或任何组件的窗口,然后调用repaint()
。
SwingUtilities.getWindowAncestor( this ).repaint();