【问题标题】:Refresh JFrame from Jinternal Frame从 Jinternalframe 刷新 JFrame
【发布时间】:2013-02-22 17:19:47
【问题描述】:

你好朋友我有一个扩展 JFrame 和 JInternalFrames 的摇摆应用程序。我需要从 JInternalFrame 中的 ActionEvent 刷新 MainFrame。 我的 MainFrame(伪)

    public class MainFrame extends JFrame{
    .................

    }
public void Refresh(){
    invalidate();
    validate();
    }

我的 JInternalFrame(Pseud0)

public class EndOfTerm extends JInternalFrame implements ActionListener{

public void actionPerformed(ActionEvent ae){

.........
new MainFrame().Refresh();

}

}

我在 ActionEvent 之后得到两帧,一帧没有组件,第二帧带有似乎重叠的组件。请帮忙。 #初学者#

【问题讨论】:

  • new MainFrame().Refresh(); 这样您正在创建大型机的新实例,而不是您应该引用启动内部框架的同一实例。如需更多帮助,请发布 SSCCE。
  • 请不要认为...,只是我的好奇心,因为我不知道任何真正的原因(代码不是SSCCE形式),你能描述一下你的原因吗,
  • 我的课程非常庞大,因为它是一个大型应用程序。
  • 不要扩展 JFrame,使用声明为局部变量的 Object,否则使用 SwingUtilities 中的方法,例如Window window = SwingUtilities.windowForComponent(Component c) 然后变量 window 与 JFrame 的局部变量相同(例如)

标签: java swing refresh


【解决方案1】:

我认为您也可以在 JInternalFrame 中调用 getParent(this) 来获取对封闭 JFrame 的引用。

【讨论】:

    【解决方案2】:

    您必须将 MainFrame 保存在 InternalFrame 中。

    public class EndOfTerm extends JInternalFrame implements ActionListener{
    
        private MainFram mainFrame;
    
        public EndOfTerm(MainFrame mainFrame) {
            this.mainFrame = mainFrame;
        }
    
        public void actionPerformed(ActionEvent ae){
    
            .........
            mainFrame.Refresh();
    
        }
    
    }
    

    当您创建 InternalFrame 时,您必须传递 MainFrame。

    new InternalFrame(this);
    

    【讨论】:

    • 你从哪里得到 NullPoinerException 异常?
    • 它正在主框架上
    • 您需要更具体。哪个方法抛出异常以及哪一行。请发布更多源代码。
    猜你喜欢
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 2013-04-04
    • 2022-01-23
    • 2014-02-25
    • 1970-01-01
    • 2010-12-01
    • 2013-05-05
    相关资源
    最近更新 更多