下面列出了java.awt.Dialog#setPreferredSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void createSelectColumnDialog() {
final ColumnSelectPanel panel = new ColumnSelectPanel(dataTable);
final JButton cancelButton = new JButton("Cancel");
final JButton okButton = new JButton("OK");
final DialogDescriptor dd = new DialogDescriptor(panel, "Select Column...", true, new Object[]{
okButton, cancelButton
}, "OK", DialogDescriptor.DEFAULT_ALIGN, null, (final ActionEvent e) -> {
if (e.getActionCommand().equals("OK")) {
try {
panel.okButtonActionPerformed(e);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
});
dd.setClosingOptions(new JButton[]{
cancelButton, okButton
});
Dialog d;
d = DialogDisplayer.getDefault().createDialog(dd);
d.pack();
d.setPreferredSize(new Dimension(200, 350));
d.setMinimumSize(new Dimension(350, 450));
d.setVisible(true);
}
public void showDialog(JComponent invoker) {
DialogDescriptor dlg = new DialogDescriptor(
this,
NbBundle.getMessage(this.getClass(), "CLIENT_EXCEPTION"), // NOI18N
false,
NotifyDescriptor.OK_CANCEL_OPTION,
DialogDescriptor.OK_OPTION,
DialogDescriptor.DEFAULT_ALIGN,
HelpCtx.DEFAULT_HELP,
null);
dlg.setOptions(new Object[] { okButton });
Dialog dialog = DialogDisplayer.getDefault().createDialog(dlg);
dialog.setPreferredSize(new Dimension(500,300));
dialog.setLocationRelativeTo(invoker);
dialog.setVisible(true);
}
static Dialog createDialog(
final String title,
final GoToPanelImpl panel,
final GoToPanelImpl.ContentProvider contentProvider,
final JButton okButton) {
okButton.setEnabled (false);
panel.getAccessibleContext().setAccessibleName( NbBundle.getMessage( GoToSymbolAction.class, "AN_GoToSymbol") ); //NOI18N
panel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage( GoToSymbolAction.class, "AD_GoToSymbol") ); //NOI18N
DialogDescriptor dialogDescriptor = new DialogDescriptor(
panel, // innerPane
title, // displayName
true,
new Object[] {okButton, DialogDescriptor.CANCEL_OPTION},
okButton,
DialogDescriptor.DEFAULT_ALIGN,
HelpCtx.DEFAULT_HELP,
new DialogButtonListener(panel, okButton));
dialogDescriptor.setClosingOptions(new Object[] {okButton, DialogDescriptor.CANCEL_OPTION});
Dialog d = DialogDisplayer.getDefault().createDialog( dialogDescriptor );
// Set size when needed
final int width = UiOptions.GoToSymbolDialog.getWidth();
final int height = UiOptions.GoToSymbolDialog.getHeight();
if (width != -1 && height != -1) {
d.setPreferredSize(new Dimension(width,height));
}
// Center the dialog after the size changed.
Rectangle r = Utilities.getUsableScreenBounds();
int maxW = (r.width * 9) / 10;
int maxH = (r.height * 9) / 10;
final Dimension dim = d.getPreferredSize();
dim.width = Math.min(dim.width, maxW);
dim.height = Math.min(dim.height, maxH);
d.setBounds(Utilities.findCenterBounds(dim));
initialDimension = dim;
d.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
contentProvider.closeDialog();
}
});
return d;
}
private Dialog createDialog( final FileSearchPanel panel) {
openBtn = new JButton();
Mnemonics.setLocalizedText(openBtn, NbBundle.getMessage(FileSearchAction.class, "CTL_Open"));
openBtn.getAccessibleContext().setAccessibleDescription(openBtn.getText());
openBtn.setEnabled( false );
final Object[] buttons = new Object[] { openBtn, DialogDescriptor.CANCEL_OPTION };
String title = NbBundle.getMessage(FileSearchAction.class, "MSG_FileSearchDlgTitle");
DialogDescriptor dialogDescriptor = new DialogDescriptor(
panel,
title,
true,
buttons,
openBtn,
DialogDescriptor.DEFAULT_ALIGN,
HelpCtx.DEFAULT_HELP,
new DialogButtonListener(panel));
dialogDescriptor.setClosingOptions(buttons);
Dialog d = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
d.getAccessibleContext().setAccessibleName(NbBundle.getMessage(FileSearchAction.class, "AN_FileSearchDialog"));
d.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FileSearchAction.class, "AD_FileSearchDialog"));
// Set size
d.setPreferredSize( new Dimension( FileSearchOptions.getWidth(),
FileSearchOptions.getHeight() ) );
// Center the dialog after the size changed.
Rectangle r = Utilities.getUsableScreenBounds();
int maxW = (r.width * 9) / 10;
int maxH = (r.height * 9) / 10;
Dimension dim = d.getPreferredSize();
dim.width = Math.min(dim.width, maxW);
dim.height = Math.min(dim.height, maxH);
initialDimension = dim;
d.setBounds(Utilities.findCenterBounds(dim));
d.addWindowListener(new WindowAdapter() {
public @Override void windowClosed(WindowEvent e) {
cleanup(false);
}
});
return d;
}
/** Creates the dialog to show
*/
private Dialog createDialog( final GoToPanel panel) {
okButton = new JButton (NbBundle.getMessage(GoToTypeAction.class, "CTL_OK"));
okButton.getAccessibleContext().setAccessibleDescription(okButton.getText());
okButton.setEnabled (false);
panel.getAccessibleContext().setAccessibleName( NbBundle.getMessage( GoToTypeAction.class, "AN_GoToType") ); //NOI18N
panel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage( GoToTypeAction.class, "AD_GoToType") ); //NOI18N
DialogDescriptor dialogDescriptor = new DialogDescriptor(
panel, // innerPane
title, // displayName
true,
new Object[] {okButton, DialogDescriptor.CANCEL_OPTION},
okButton,
DialogDescriptor.DEFAULT_ALIGN,
HelpCtx.DEFAULT_HELP,
new DialogButtonListener( panel ) ); // Action listener
dialogDescriptor.setClosingOptions(new Object[] {okButton, DialogDescriptor.CANCEL_OPTION});
// panel.addPropertyChangeListener( new HelpCtxChangeListener( dialogDescriptor, helpCtx ) );
// if ( panel instanceof HelpCtx.Provider ) {
// dialogDescriptor.setHelpCtx( ((HelpCtx.Provider)panel).getHelpCtx() );
// }
Dialog d = DialogDisplayer.getDefault().createDialog( dialogDescriptor );
// Set size when needed
final int width = UiOptions.GoToTypeDialog.getWidth();
final int height = UiOptions.GoToTypeDialog.getHeight();
if (width != -1 && height != -1) {
d.setPreferredSize(new Dimension(width,height));
}
// Center the dialog after the size changed.
Rectangle r = Utilities.getUsableScreenBounds();
int maxW = (r.width * 9) / 10;
int maxH = (r.height * 9) / 10;
final Dimension dim = d.getPreferredSize();
dim.width = Math.min(dim.width, maxW);
dim.height = Math.min(dim.height, maxH);
d.setBounds(Utilities.findCenterBounds(dim));
initialDimension = dim;
d.addWindowListener(new WindowAdapter() {
public @Override void windowClosed(WindowEvent e) {
cleanup();
}
});
return d;
}