下面的代码使 JInternalFrame 在 JFrame 内的 JDesktopPane 上弹出
JInternalPane adf = new JInternalpane();
JDesktopPane.add(adf);
adf.show();
但是当InternalFrame图标化或在DesktopPane上仍然可见并且再次单击使InternalFrame显示的Action_Button时,会再次弹出另一个相同类型的InternalFrame。并且随着按钮的点击而不断弹出。
请问我们如何生成这样的代码,如果单击按钮,它应该首先检查internalFrame是否被图标化并使其再次可见。而不是弹出另一个内部框架。
我正在使用带有jdk 8的netbeans ide。
当我右键单击按钮,选择事件,然后执行操作时,将执行button_action,到目前为止我只编写了这段代码。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JInternalPane adf = new JInternalpane();
JDesktopPane.add(adf);
adf.show();
// TODO add your handling code here:
}
谢谢
最佳答案
您需要为内部框架保留一个实例变量,以便了解当前状态。
那么 ActionListener 中的代码将类似于:
if (internalFrame == null) // not yet created
{
internalFrame = new JInternalFrame(...);
desktopPane.add( internalFrame );
internalFrame.show();
}
else if (internal frame is iconified) // read the API for the method to use
{
// show the internal frame
}
关于java - 单击按钮使 JInternalFrame 即使在最小化时也出现一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51364969/