gpt4 book ai didi

java - 如何在 Swing 中为 JDialog 重绘?

转载 作者:行者123 更新时间:2023-11-29 08:12:44 52 4
gpt4 key购买 nike

如何在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,但新的未添加到布局中

关于java - 如何在 Swing 中为 JDialog 重绘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7105933/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com