java - 如何将所有打开的 jinternalframe 中的 jinternalframe 置于前面?

标签 java swing netbeans jinternalframe

这是我的源代码。 我无法将我的 JInternalframe 放到前面。 我已经尝试了很多代码,但没有任何效果。

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    boolean b = true;
    JInternalFrame[] j = jDesktopPane1.getAllFrames();
    no = new NewOrder();

    for (JInternalFrame Ji : j) {
        if (Ji.isShowing()) {
            b = false;
            break;
        }
    }

    if (!b) {
      no.requestFocus(true);
    } else {
        dm = jDesktopPane1.getDesktopManager();
        jDesktopPane1.add(no);
        dm.setBoundsForFrame(no, (jDesktopPane1.getWidth() - no.getWidth()) / 2, (jDesktopPane1.getHeight() - no.getHeight()) / 2, no.getWidth(), no.getHeight());
        dm.openFrame(no);
        no.setVisible(true);
    }


} 

NewOrder no = new NewOrder();

if (no.isShowing()) {
    no.toFront();
} else {
    lo.LoadInterfaces(no, jDesktopPane1);
}

任何人都可以解释一下为什么会发生这种情况吗? 谢谢!

最佳答案

使用setSelected()方法JInternalFrame ;引用了一个完整的例子here 。为了方便起见,请从 Action 调用该方法。 ,如图here .

附录:典型的实现可能如下所示。

class MyFrame extends JInternalFrame {

    private Action action;

    MyFrame(…) {
        …
        action = new AbstractAction(name) {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    MyFrame.this.setSelected(true);
                } catch (PropertyVetoException e) {
                    e.printStackTrace();
                }
            }
        };
    }

    public Action getAction() {
        return action;
    }
}

关于java - 如何将所有打开的 jinternalframe 中的 jinternalframe 置于前面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26699125/

相关文章:

java - 如何在关闭 jframe 之前询问我是否已保存文本文档

java - 如何在不可编辑的 JTextField 中显示图像?

java - 正确对齐控制台输出表中的列并从零开始计数

java - 如何退出 NetBeans 平台 GUI 应用程序?

java - RingtoneManager 返回空铃声

使用 SecretKeyFactory 生成 secret 时,Java 字节数组到字符串必须等于 python 字节数组字符串

java - flash.display.Loader 间歇性地导致加载的 swf 的子项松散类型

java - 使用 Java Annotation 不运行方法

java - 编程 Java Swing、Flex 等

java - 构建后使用 getResourceAsStream 不起作用?