繁体   English   中英

如何在Swing中为JDialog进行重绘?

[英]How to make repaint for JDialog in Swing?

如何在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方法中更改组件。

代替

legdetailsTable = new JTable(mytablemodel);

legdetailsTable.setModel(mytablemodel);

您重新创建JTable,但新布局未添加到布局中

您可以获取当前组件或任何组件的窗口,然后调用repaint()

SwingUtilities.getWindowAncestor( this ).repaint(); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM