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

发布于 2024-11-30 03:05:29 字数 1150 浏览 6 评论 0原文

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

How to make repaint for JDialog in Swing?
If I click on convert button in JDialog I need to change GUI design of JDialog but it's not happening? 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 .

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半﹌身腐败 2024-12-07 03:05:29

您重新创建 JTable,而不是

legdetailsTable = new JTable(mytablemodel);

添加

legdetailsTable.setModel(mytablemodel);

,但新的 JTable 未添加到布局中

Instead of

legdetailsTable = new JTable(mytablemodel);

add

legdetailsTable.setModel(mytablemodel);

You recreate JTable but the new one isn't added to layout

白日梦 2024-12-07 03:05:29

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

SwingUtilities.getWindowAncestor( this ).repaint(); 

You can get the Window of the current Component or any Component and than call repaint().

SwingUtilities.getWindowAncestor( this ).repaint(); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文