如何在JApplet中显示一个JDialog,并让其在屏幕居中显示
先把JDialog的类创建好,在Netbeans中通过GUI的界面可以把界面画好。然后调用的方法是这样:
Frame f = (Frame)SwingUtilities.getAncestorOfClass(Frame.class, this);
AddNodeDialog and = new AddNodeDialog(f, props.getProperty("setsharetree.addnodedlg.title"), true);
and.setProps(props);
and.setUserListString(allUserString);
and.setPrjListString(allProjectString);
and.setDeptListString(allDeptString);
and.customInit();
// Define AddNodeDialog Postion
int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
and.setLocation((screenWidth - and.getSize().width) / 2, (screenHeight - and.getSize().height) / 2);
and.pack();
and.setVisible(true);
AddNodeDialog and = new AddNodeDialog(f, props.getProperty("setsharetree.addnodedlg.title"), true);
and.setProps(props);
and.setUserListString(allUserString);
and.setPrjListString(allProjectString);
and.setDeptListString(allDeptString);
and.customInit();
// Define AddNodeDialog Postion
int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
and.setLocation((screenWidth - and.getSize().width) / 2, (screenHeight - and.getSize().height) / 2);
and.pack();
and.setVisible(true);