JDesktopPane和JInternalFrame帮助!

时间:2011-01-04 04:06:24

标签: java collections jinternalframe jlayeredpane jdesktoppane

问候,

我有一个关于将重复的JInternalFrame限制为JDesktopPane的问题。 基本上,将实例JInternalFrame添加到JDesktopPane是全面的。 但是,在JDesktopPane上限制同一实例的重复JInternalFrame,并将该实例设置为JDesktopPane的顶层。

我怎么能实现这个? 我是否要将所有实例存储到ArrayList并检查是否已经打开了关于执行的实例?

您的回复非常感谢。

谢谢, Cyril H。

1 个答案:

答案 0 :(得分:0)

/**
 * method to search for active internal frame windows
 * and return true or false depending on the outcome. this method uses internalframe names
 */
public boolean searchIFrame(String search, JInternalFrame frame[])
{
    for(int i = 0; i < frame.length; i++)
        if(frame[i].getTitle().toString().equals(search))
            return true;
        return false;
}

//its implementation in your program. "Information Form" is the internalframe's name
//jdesk is the desktoppane object or instance
boolean srch = searchIFrame("Information Form", jdesk.getAllFrames());
    if(!srch) {        
                VisitationForm at = new VisitationForm();
                at.pack();
                jdesk.add(at);

                try
                {
                    at.setSelected(true);
                    at.setVisible(true);
                    // We're done, so clear the feedback message
                    //bar.setString(" ");
                    //bar.setIndeterminate(false);
                    at.requestFocus();

                }
                catch (PropertyVetoException pve)
                {
                    //bar.setString(" ");
                    //bar.setIndeterminate(false);

                    // Then display the error in a dialog box
                    System.out.println(pve);
                }

            }