本文整理了Java中javax.swing.JDialog.pack()
方法的一些代码示例,展示了JDialog.pack()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JDialog.pack()
方法的具体详情如下:
包路径:javax.swing.JDialog
类名称:JDialog
方法名:pack
暂无
代码示例来源:origin: stackoverflow.com
final JDialog frame = new JDialog(parentFrame, frameTitle, true);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
代码示例来源:origin: deathmarine/Luyten
protected JDialog createDialog(Component parent) {
Frame frame = parent instanceof Frame ? (Frame) parent
: (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
JDialog dialog = new JDialog(frame, ("Select Font"), true);
Action okAction = new DialogOKAction(dialog);
Action cancelAction = new DialogCancelAction(dialog);
JButton okButton = new JButton(okAction);
okButton.setFont(DEFAULT_FONT);
JButton cancelButton = new JButton(cancelAction);
cancelButton.setFont(DEFAULT_FONT);
JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new GridLayout(2, 1));
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));
ActionMap actionMap = buttonsPanel.getActionMap();
actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));
JPanel dialogEastPanel = new JPanel();
dialogEastPanel.setLayout(new BorderLayout());
dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);
dialog.getContentPane().add(this, BorderLayout.CENTER);
dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
dialog.pack();
dialog.setLocationRelativeTo(frame);
return dialog;
}
代码示例来源:origin: stackoverflow.com
final JOptionPane optionPane = new JOptionPane("Hello world", JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[]{}, null);
final JDialog dialog = new JDialog();
dialog.setTitle("Message");
dialog.setModal(true);
dialog.setContentPane(optionPane);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.pack();
//create timer to dispose of dialog after 5 seconds
Timer timer = new Timer(5000, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ae) {
dialog.dispose();
}
});
timer.setRepeats(false);//the timer should only go off once
//start timer to close JDialog as dialog modal we must start the timer before its visible
timer.start();
dialog.setVisible(true);
代码示例来源:origin: groovy/groovy-core
FIND_REPLACE_DIALOG.pack();
FIND_REPLACE_DIALOG.setLocationRelativeTo(frames[i]);
FIND_REPLACE_DIALOG.setVisible(true);
FIND_FIELD.requestFocusInWindow();
代码示例来源:origin: stackoverflow.com
public void makeGui() {
aPanel = new JPanel(new BorderLayout());
this.getContentPane().add(aPanel, BorderLayout.CENTER);
Window win = SwingUtilities.getWindowAncestor(Example.this);
JDialog dialog = new JDialog(win, "My Dialog", ModalityType.MODELESS);
JPanel dialogPanel = new JPanel();
dialogPanel.setPreferredSize(new Dimension(200, 200));
dialog.add(dialogPanel);
dialog.pack();
dialog.setVisible(true);
JOptionPane.showMessageDialog(dialog, "arfarf");
}
代码示例来源:origin: geotools/geotools
final JDialog dialog = new JDialog((Frame) owner, title);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.addWindowListener(listener);
dialog.getContentPane().add(panel);
dialog.pack();
return dialog;
final JDialog dialog = new JDialog((Dialog) owner, title);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.addWindowListener(listener);
dialog.getContentPane().add(panel);
dialog.pack();
return dialog;
代码示例来源:origin: org.cytoscape/vizmap-gui-impl
private void initComponents(final JDialog dialog) {
dialog.setLayout(new BorderLayout());
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.getContentPane().add(editorPanel, BorderLayout.CENTER);
dialog.setPreferredSize(DEF_SIZE);
dialog.setMinimumSize(MIN_SIZE);
dialog.pack();
}
});
代码示例来源:origin: cytoscape.corelibs/task
/**
* Initializes UI.
*/
private void initUI() {
// Use Border Layout
setLayout(new BorderLayout());
// Create North Panel with Error Message and Button.
JPanel northPanel = createNorthPanel();
add(northPanel, BorderLayout.NORTH);
// Create Center Panel with Error Details.
JScrollPane centerPanel = createCenterPanel();
add(centerPanel, BorderLayout.CENTER);
// Repack and validate the owner
owner.pack();
owner.validate();
}
代码示例来源:origin: libgdx/libgdx
@Override
public void actionPerformed (ActionEvent arg0) {
if(editor.isUsingDefaultTexture()) {
JOptionPane.showMessageDialog(editor, "Load a Texture or an Atlas first.");
return;
}
TextureAtlas atlas = editor.getAtlas();
if(atlas != null)
regionPickerPanel.setAtlas(atlas);
else
regionPickerPanel.setTexture(editor.getTexture());
regionPickerPanel.revalidate();
regionPickerPanel.repaint();
regionSelectDialog.validate();
regionSelectDialog.repaint();
regionSelectDialog.pack();
regionSelectDialog.setVisible(true);
}
});
代码示例来源:origin: protegeproject/protege
private static JDialog createDialog(Component parent, String title, JOptionPane optionPane, final JComponent defaultFocusedComponent) {
JDialog dlg = optionPane.createDialog(parent, title);
dlg.setLocationRelativeTo(parent);
dlg.setResizable(true);
dlg.pack();
return dlg;
}
代码示例来源:origin: igniterealtime/Openfire
private void installPlugin(final File plugin) {
final JDialog dialog = new JDialog(frame, "Installing Plugin", true);
dialog.getContentPane().setLayout(new BorderLayout());
JProgressBar bar = new JProgressBar();
bar.setIndeterminate(true);
bar.setString("Installing Plugin. Please wait...");
bar.setStringPainted(true);
dialog.getContentPane().add(bar, BorderLayout.CENTER);
dialog.pack();
dialog.setSize(225, 55);
dialog.setLocationRelativeTo(frame);
dialog.setVisible(true);
代码示例来源:origin: stanfordnlp/CoreNLP
final JDialog dialog = new JDialog(frame, "Jar File Chooser", true);
dialog.setLocation(location);
final JList fileList = new JList(new Vector<>(files));
okay.setText("Okay");
okay.setToolTipText("Okay");
okay.addActionListener(evt -> dialog.setVisible(false));
JButton cancel = new javax.swing.JButton();
cancel.setText("Cancel");
cancel.addActionListener(evt -> {
fileList.clearSelection();
dialog.setVisible(false);
});
gridbag.setConstraints(cancel, constraints);
dialog.add(cancel);
dialog.pack();
dialog.setSize(dialog.getPreferredSize());
dialog.setVisible(true);
代码示例来源:origin: org.ihtsdo/wb-api
public void showNonModalDialog() {
wizardDialog.setModal(false);
wizardDialog.pack();
wizardDialog.setLocationRelativeTo(null); // center frame
wizardDialog.setVisible(true);
}
代码示例来源:origin: ontop/ontop
public static JDialog createDialogForPanel(JFrame parent, JPanel panel) {
JDialog newdialog = new JDialog(parent);
newdialog.getContentPane().add(panel, java.awt.BorderLayout.CENTER);
newdialog.pack();
return newdialog;
}
代码示例来源:origin: libgdx/libgdx
@Override
public void actionPerformed (ActionEvent arg0) {
if(editor.isUsingDefaultTexture()) {
JOptionPane.showMessageDialog(editor, "Load a Texture or an Atlas first.");
return;
}
TextureAtlas atlas = editor.getAtlas();
if(atlas != null)
regionPickerPanel.setAtlas(atlas);
else
regionPickerPanel.setTexture(editor.getTexture());
regionPickerPanel.revalidate();
regionPickerPanel.repaint();
regionSelectDialog.validate();
regionSelectDialog.repaint();
regionSelectDialog.pack();
regionSelectDialog.setVisible(true);
}
});
代码示例来源:origin: protegeproject/protege
private static JDialog createDialog(JComponent parent, String title, JOptionPane optionPane) {
JDialog dlg = optionPane.createDialog(parent, title);
dlg.setLocationRelativeTo(parent);
dlg.setResizable(true);
dlg.pack();
return dlg;
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
JPanel textPanel = new JPanel(new BorderLayout());
textPanel.setPreferredSize(new Dimension(100,100));
textPanel.add(text);
System.out.println("encoding null!!");
setEncoding.setText(encoding);
dialog.setVisible(false);
});
useOldEncoding.addActionListener(e -> dialog.setVisible(false));
useAnotherEncoding.addActionListener(e -> {
dialog.setVisible(false);
alternateEncodingPrompt(encoding);
});
dialog.getRootPane().setDefaultButton(useNewEncoding);
dialog.pack();
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
代码示例来源:origin: marytts/marytts
private void showProgressPanel(List<ComponentDescription> comps, boolean install) {
final ProgressPanel pp = new ProgressPanel(comps, install);
final JOptionPane optionPane = new JOptionPane(pp, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
new String[] { "Abort" }, "Abort");
// optionPane.setPreferredSize(new Dimension(640,480));
final JDialog dialog = new JDialog((Frame) null, "Progress", false);
dialog.setContentPane(optionPane);
optionPane.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
pp.requestExit();
dialog.setVisible(false);
}
}
});
dialog.pack();
dialog.setVisible(true);
new Thread(pp).start();
}
代码示例来源:origin: xyz.cofe/docking-frames-common
/**
* Opens the dialog relative to <code>relativeTo</code>.
* @param relativeTo some component
*/
public void open( Component relativeTo ){
dialog.pack();
dialog.setLocationRelativeTo( relativeTo );
validateBounds();
dialog.setVisible( true );
}
代码示例来源:origin: ontop/ontop
public static JDialog createDialogForPanel(JDialog parent, JPanel panel) {
JDialog newdialog = new JDialog(parent);
newdialog.getContentPane().add(panel, java.awt.BorderLayout.CENTER);
newdialog.pack();
return newdialog;
}
内容来源于网络,如有侵权,请联系作者删除!