当我调用我的显示功能时,我的页面永远不会刷新

时间:2016-04-26 05:28:21

标签: java user-interface jframe

我正在尝试创建一个获取XML信息然后取代用户界面的程序。该界面应具有将用户返回主页或返回上一页的按钮(如果它们不在主页上)。页面也应该有一个按钮,它将运行我认为正确写入的显示功能,以显示到目前为止所写的程序。但是,当我运行程序并单击按钮时没有任何反应。我已经尝试在调试模式下运行该程序,并已验证XML确实正确解析并且程序识别出按钮被按下并且页面应该更改。这是显示函数,如下所示:

public void display(String pageShortName){
    this.setTitle(projectTitle + ": " );//sets the window title to project title plus window name
    currentPageShortName = pageShortName;
    this.getContentPane();
    JPanel toolBar = new JPanel();//create a new panel
    JPanel childButtonBar = new JPanel();
    toolBar.setPreferredSize(new Dimension(this.WIDTH, 100));//set the prefered size to the width of the screen and 100 tall
    childButtonBar.setPreferredSize(new Dimension(this.WIDTH, 200));

    toolBar.setAlignmentY(TOP_ALIGNMENT);
    toolBar.setAlignmentX(CENTER_ALIGNMENT);
    childButtonBar.setAlignmentY(CENTER_ALIGNMENT);
    childButtonBar.setAlignmentX(CENTER_ALIGNMENT);
    if(c.linkIdList.get(pageShortName).hasHomeButton()){//if the page has a home button
        toolBar.add(new ChildButton("Home", c.linkIdList.get("home").getShortName(), this));//add a home button to the tool bar
    }
    if(c.linkIdList.get(pageShortName).hasBackButton()){//if the page has a back button
        toolBar.add(new ChildButton("Back", previousPageShortName, this));//add a back button to the page
    }
    if(c.linkIdList.get(pageShortName).hasChildButtons()){
        for(int i = 0; i<c.linkIdList.get(pageShortName).getButtonList().size(); i+=1){
            XMLButton currentXMLButton = c.linkIdList.get(pageShortName).getButtonList().get(i);
            childButtonBar.add(new ChildButton(currentXMLButton.name, currentXMLButton.linkShortName, this));
        }
    }

    this.add(toolBar, BorderLayout.PAGE_START);//add the tool bar to the top of the screen
    this.add(childButtonBar, BorderLayout.PAGE_END);
    this.revalidate();//first step of redraw
    this.repaint();//second step of redraw
}

这是按下按钮时的动作监听器功能:

public void actionPerformed(ActionEvent e){
     userInt.previousPageShortName = userInt.currentPageShortName;
     userInt.display(linkShortName);
 }

任何人都可以帮我找到按下按钮时不会更新的原因。

1 个答案:

答案 0 :(得分:0)

更新JFrame或JComponent

this.validate();

需要被称为