如何在Swing中重写JDialog?

时间:2011-08-18 10:25:05

标签: java swing repaint 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方法中的组件。

2 个答案:

答案 0 :(得分:3)

而不是

legdetailsTable = new JTable(mytablemodel);

添加

legdetailsTable.setModel(mytablemodel);

您重新创建JTable,但新的不会添加到布局

答案 1 :(得分:2)

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

SwingUtilities.getWindowAncestor( this ).repaint();