这是我的源代码。
我无法将我的 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/