下面列出了java.awt.Dialog#setResizable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public boolean showDialog() {
DialogDescriptor dialogDescriptor = new DialogDescriptor(panel,
org.openide.util.NbBundle.getMessage(RevertModifications.class, "CTL_UpdateDialog", repository.getName()), // NOI18N
true,
new Object[] {okButton, cancelButton},
okButton,
DialogDescriptor.DEFAULT_ALIGN,
new HelpCtx(this.getClass()),
null);
dialogDescriptor.setValid(false);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(RevertModifications.class, "ACSD_UpdateDialog", repository.getName())); // NOI18N
dialog.setVisible(true);
dialog.setResizable(false);
boolean ret = dialogDescriptor.getValue() == okButton;
return ret;
}
public static void makeOwningDialogResizable(@Nonnull final Component component, @Nonnull @MustNotContainNull final Runnable... extraActions) {
final HierarchyListener listener = new HierarchyListener() {
@Override
public void hierarchyChanged(@Nonnull final HierarchyEvent e) {
final Window window = SwingUtilities.getWindowAncestor(component);
if (window instanceof Dialog) {
final Dialog dialog = (Dialog) window;
if (!dialog.isResizable()) {
dialog.setResizable(true);
component.removeHierarchyListener(this);
for (final Runnable r : extraActions) {
r.run();
}
}
}
}
};
component.addHierarchyListener(listener);
}
public void performAction () {
DialogDescriptor descriptor = new DialogDescriptor(
new org.netbeans.core.ui.ProductInformationPanel (),
NbBundle.getMessage(AboutAction.class, "About_title"),
true,
new Object[0],
null,
DialogDescriptor.DEFAULT_ALIGN,
null,
null);
Dialog dlg = null;
try {
dlg = DialogDisplayer.getDefault().createDialog(descriptor);
if( Utilities.isMac() && dlg instanceof JDialog ) {
JDialog d = (JDialog) dlg;
InputMap map = d.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.META_MASK), "Escape"); //NOI18N
//#221571
d.getRootPane().putClientProperty("nb.about.dialog", Boolean.TRUE); //NOI18N
}
dlg.setResizable(false);
dlg.setVisible(true);
} finally {
if (dlg != null) {
dlg.dispose();
}
}
}
public boolean showDialog() {
DialogDescriptor dialogDescriptor = new DialogDescriptor(panel, org.openide.util.NbBundle.getMessage(UpdateTo.class, "CTL_UpdateToDialog")); // NOI18N
dialogDescriptor.setOptions(new Object[] {okButton, cancelButton});
dialogDescriptor.setModal(true);
dialogDescriptor.setHelpCtx(new HelpCtx(this.getClass()));
dialogDescriptor.setValid(false);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateTo.class, "ACSD_UpdateToDialog")); // NOI18N
dialog.setVisible(true);
dialog.setResizable(false);
boolean ret = dialogDescriptor.getValue() == okButton;
return ret;
}
public boolean showDialog() {
DialogDescriptor dialogDescriptor = new DialogDescriptor(panel, org.openide.util.NbBundle.getMessage(RevertModifications.class, "CTL_RevertDialog")); // NOI18N
dialogDescriptor.setOptions(new Object[] {okButton, cancelButton});
dialogDescriptor.setModal(true);
dialogDescriptor.setHelpCtx(new HelpCtx(this.getClass()));
dialogDescriptor.setValid(false);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(RevertModifications.class, "ACSD_RevertDialog")); // NOI18N
dialog.setVisible(true);
dialog.setResizable(false);
boolean ret = dialogDescriptor.getValue() == okButton;
return ret;
}
@Override
public boolean askPassword(ExecutionEnvironment execEnv, String key) {
Mnemonics.setLocalizedText(promptLabel, NbBundle.getMessage(CertPassphraseDlg.class, "CertPassphraseDlg.promptLabel.text", key)); // NOI18N
tfUser.setText(execEnv.getUser());
String hostName = execEnv.getHost();
if (execEnv.getSSHPort() != 22) {
hostName += ":" + execEnv.getSSHPort(); //NOI18N
}
tfHost.setText(hostName); // NOI18N
DialogDescriptor dd = new DialogDescriptor(this,
NbBundle.getMessage(CertPassphraseDlg.class, "CertPassphraseDlg.title.text"), // NOI18N
true, // NOI18N
new Object[]{
DialogDescriptor.OK_OPTION,
DialogDescriptor.CANCEL_OPTION},
DialogDescriptor.OK_OPTION,
DialogDescriptor.DEFAULT_ALIGN, null, null);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
dialog.setResizable(false);
try {
dialog.setVisible(true);
} catch (Throwable th) {
if (!(th.getCause() instanceof InterruptedException)) {
throw new RuntimeException(th);
}
dd.setValue(DialogDescriptor.CANCEL_OPTION);
} finally {
dialog.dispose();
}
return dd.getValue() == DialogDescriptor.OK_OPTION;
}
@Override
public boolean askPassword(ExecutionEnvironment execEnv, String prompt) {
tfUser.setText(execEnv.getUser());
String hostName = execEnv.getHost();
if (execEnv.getSSHPort() != 22) {
hostName += ":" + execEnv.getSSHPort(); //NOI18N
}
tfHost.setText(hostName); // NOI18N
cbRememberPwd.setSelected(PasswordManager.getInstance().isRememberPassword(execEnv));
DialogDescriptor dd = new DialogDescriptor(this,
loc("TITLE_Password"), true, // NOI18N
new Object[]{
DialogDescriptor.OK_OPTION,
DialogDescriptor.CANCEL_OPTION},
DialogDescriptor.OK_OPTION,
DialogDescriptor.DEFAULT_ALIGN, null, null);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
dialog.setResizable(false);
try {
dialog.setVisible(true);
} catch (Throwable th) {
if (!(th.getCause() instanceof InterruptedException)) {
throw new RuntimeException(th);
}
dd.setValue(DialogDescriptor.CANCEL_OPTION);
} finally {
dialog.dispose();
}
return dd.getValue() == DialogDescriptor.OK_OPTION;
}
/**
*
* @param auth
* @return false if cancelled
*/
public boolean initAuthentication(final Authentication auth) {
AuthenticationSettingsPanel vpanel = new AuthenticationSettingsPanel(auth, false);
vpanel.addValidationListener(new AuthValidationListener());
cfgPanel.add(vpanel, BorderLayout.CENTER);
DialogDescriptor dd = new DialogDescriptor(this,
NbBundle.getMessage(AuthTypeSelectorDlg.class, "TITLE_AuthTypeSelectorDlg"), // NOI18N
true, new Object[]{ok, DialogDescriptor.CANCEL_OPTION}, ok,
DialogDescriptor.DEFAULT_ALIGN, null, null);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
dialog.setResizable(false);
try {
dialog.setVisible(true);
} catch (Throwable th) {
if (!(th.getCause() instanceof InterruptedException)) {
throw new RuntimeException(th);
}
dd.setValue(DialogDescriptor.CANCEL_OPTION);
} finally {
dialog.dispose();
}
if (dd.getValue() == ok) {
vpanel.applyChanges(null);
return true;
} else {
return false;
}
}
public boolean showDialog() {
DialogDescriptor dialogDescriptor = new DialogDescriptor(panel, org.openide.util.NbBundle.getMessage(Clone.class, "CTL_CloneDialog"), // NOI18N
true, new Object[] {okButton, cancelButton}, okButton, DialogDescriptor.DEFAULT_ALIGN, new HelpCtx(this.getClass()), null);
dialogDescriptor.setValid(false);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(Clone.class, "ACSD_CloneDialog")); // NOI18N
dialog.setVisible(true);
dialog.setResizable(false);
boolean ret = dialogDescriptor.getValue() == okButton;
return ret;
}
@Override
public void hierarchyChanged(HierarchyEvent e) {
Window window = SwingUtilities.getWindowAncestor(pane);
if (window instanceof Dialog) {
Dialog dialog = (Dialog) window;
if (!dialog.isResizable()) {
dialog.setResizable(true);
}
}
}
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
for(int i = 0; i < 10; i++) {
Dialog dialog = new Dialog((Frame) null);
dialog.setLocation(100, 100);
Component panel = new Panel();
panel.setPreferredSize(new Dimension(200, 100));
dialog.add(panel);
dialog.pack();
dialog.setVisible(true);
robot.waitForIdle();
robot.delay(200);
Point frameLoc = dialog.getLocationOnScreen();
Point contentLoc = panel.getLocationOnScreen();
System.out.println("Decor location " + frameLoc);
System.out.println("Content location " + contentLoc);
dialog.setResizable(false);
robot.waitForIdle();
robot.delay(200);
Point l = dialog.getLocationOnScreen();
if (!l.equals(frameLoc)) {
dialog.dispose();
throw new RuntimeException("Decorated frame location moved " +
"after setResizable(false)" + l);
}
l = panel.getLocationOnScreen();
if (!l.equals(contentLoc)) {
dialog.dispose();
throw new RuntimeException("Content location moved after " +
"setResizable(false)" + l);
}
if (panel.getLocationOnScreen().y <
dialog.getLocationOnScreen().y + dialog.getInsets().top) {
dialog.dispose();
throw new RuntimeException(
"Wrong content position after setResizable(false)");
}
dialog.setResizable(true);
robot.waitForIdle();
robot.delay(200);
l = dialog.getLocationOnScreen();
if (!l.equals(frameLoc)) {
dialog.dispose();
throw new RuntimeException("Decorated frame location moved " +
"after setResizable(true)" + l);
}
l = panel.getLocationOnScreen();
if (!l.equals(contentLoc)) {
dialog.dispose();
throw new RuntimeException("Content location moved after " +
"setResizable(true)" + l);
}
if (panel.getLocationOnScreen().y <
dialog.getLocationOnScreen().y + dialog.getInsets().top) {
dialog.dispose();
throw new RuntimeException(
"Wrong content position after setResizable(true)");
}
dialog.dispose();
}
}
private void addZipButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addZipButtonActionPerformed
final CIEntry entry = new CIEntry();
final CIEntryEditPanel panel = new CIEntryEditPanel();
panel.load(entry);
panel.setFileEntryMap(model.getEntryMap());
final DialogDescriptor descriptor = new DialogDescriptor(
panel,
getMessage("CTL_AddArchiveFile"), // NOI18N
true,
NotifyDescriptor.OK_CANCEL_OPTION,
NotifyDescriptor.OK_OPTION,
null);
descriptor.setClosingOptions(new Object[]{});
NotificationLineSupport notificationLineSupport = descriptor.createNotificationLineSupport();
panel.setValidityObjects(descriptor, notificationLineSupport);
final Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor);
dialog.getAccessibleContext().setAccessibleName(getMessage("ACSN_Dialog")); // NOI18N
dialog.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_Dialog")); // NOI18N
dialog.setResizable(false);
descriptor.setButtonListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (DialogDescriptor.OK_OPTION.equals(e.getSource())) {
}
dialog.setVisible(false);
}
});
dialog.setVisible(true);
if (NotifyDescriptor.OK_OPTION.equals(descriptor.getValue())) {
panel.store(entry);
model.addEntry(entry);
int rowIndex = entryTable.getRowCount() - 1;
entryTable.setRowSelectionInterval(rowIndex, rowIndex);
}
dialog.dispose();
}
private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
int rowIndex = entryTable.getSelectedRow();
if (rowIndex >= 0) {
final CIEntry entry = model.getEntry(rowIndex);
final CIEntryEditPanel panel = new CIEntryEditPanel();
panel.load(entry);
panel.setFileEntryMap(model.getEntryMap(entry));
final DialogDescriptor descriptor = new DialogDescriptor(
panel,
getMessage("CTL_AddArchiveFile"), // NOI18N
true,
NotifyDescriptor.OK_CANCEL_OPTION,
NotifyDescriptor.OK_OPTION,
null);
descriptor.setClosingOptions(new Object[]{});
NotificationLineSupport notificationLineSupport = descriptor.createNotificationLineSupport();
panel.setValidityObjects(descriptor, notificationLineSupport);
final Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor);
dialog.getAccessibleContext().setAccessibleName(getMessage("ACSN_Dialog")); // NOI18N
dialog.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_Dialog")); // NOI18N
dialog.setResizable(false);
descriptor.setButtonListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (DialogDescriptor.OK_OPTION.equals(e.getSource())) {
}
dialog.setVisible(false);
}
});
dialog.setVisible(true);
if (NotifyDescriptor.OK_OPTION.equals(descriptor.getValue())) {
panel.store(entry);
model.setEntry(rowIndex, entry);
entryTable.setRowSelectionInterval(rowIndex, rowIndex);
}
dialog.dispose();
}
}
private static Dialog dialogImpl(String caption, Object message, int type, Object... options) {
DialogDescriptor dd = new DialogDescriptor(message, caption);
dd.setMessageType(type);
dd.setOptions(options);
Dialog d = DialogDisplayer.getDefault().createDialog(dd);
d.setIconImages(getIcons());
d.setResizable(false);
return d;
}