如何在Swing中对JDialog进行重绘?
如何在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方法中的组件。
您可以获取当前Component或任何Component的Window,而不是调用repaint()
。
SwingUtilities.getWindowAncestor( this ).repaint();
代替
legdetailsTable = new JTable(mytablemodel);
加
legdetailsTable.setModel(mytablemodel);
您重新创建JTable,但新的JTable不会添加到布局中