简体   繁体   English

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

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

How to make repaint for JDialog in Swing? 如何在Swing中为JDialog进行重绘? If I click on convert button in JDialog I need to change GUI design of JDialog but it's not happening? 如果我在JDialog中单击转换按钮,则需要更改JDialog的GUI设计,但是没有发生吗? Is their any solution? 他们有什么解决方案吗?

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

I'm setting booking type id is 13 . 我将预订类型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);
}

Using Id I'm changing componenents in initcomponents method. 使用Id我正在initcomponents方法中更改组件。

Instead of 代替

legdetailsTable = new JTable(mytablemodel);

add

legdetailsTable.setModel(mytablemodel);

You recreate JTable but the new one isn't added to layout 您重新创建JTable,但新布局未添加到布局中

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

SwingUtilities.getWindowAncestor( this ).repaint(); 

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

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