使用Id来改变initcomponents方法中的组件
如何在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);
}
代替
legdetailsTable = new JTable(mytablemodel);
添加legdetailsTable.setModel(mytablemodel);
您重新创建了JTable,但是新的JTable没有添加到布局
您可以获取当前组件或任何组件的窗口,然后调用repaint()
。
SwingUtilities.getWindowAncestor( this ).repaint();