如何在JdesktopPane的中心设置Visible JinternalFrame? [英] How to setVisible a JinternalFrame in the center of the JdesktopPane?

查看:52
本文介绍了如何在JdesktopPane的中心设置Visible JinternalFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我想在JDesktopPane的中心显示JinternalFrame,并且我在Jframes中使用它时使用了该方法,但是它没有用:

Actually i wanna show the JinternalFrame in the center of the JDesktopPane and i used this methode as i use it in Jframes but it didn't work :

Extraction ex=new Extraction();//Extraction is the name of the JintenalFrame jDesktopPane1.add(ex); ex.setLocationRelativeTo(this); ex.setVisible(true);

Extraction ex=new Extraction();//Extraction is the name of the JintenalFrame jDesktopPane1.add(ex); ex.setLocationRelativeTo(this); ex.setVisible(true);

所以我要问是否还有另一种方法,以便可以在JdesktoPane的中心显示JinternalFrame. 谢谢

So i am asking if there is another methode so i can display the JinternalFrame in the center of the JdesktoPane. Thank you

推荐答案

javax.swing.JInternalFrame缺少java.awt.Window中方便的setLocationRelativeTo(null)实现,但是您可以使用类似的方法.只需从桌面窗格的相应中心坐标中减去内部框架的宽度和高度的一半即可.在呼叫setLocation()时使用新坐标.

A javax.swing.JInternalFrame lacks the convenient setLocationRelativeTo(null) implementation found in java.awt.Window, but you can use a similar approach. Just subtract half the width and height of the internal frame from the corresponding center coordinates of the desktop pane. Use the new coordinates in your call to setLocation().

如果需要,您还需要调整内部框架的尺寸.

You'll also want to adjust the internal frame's dimensions if necessary.

这篇关于如何在JdesktopPane的中心设置Visible JinternalFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆