本文整理汇总了Java中javax.swing.JOptionPane.createDialog方法的典型用法代码示例。如果您正苦于以下问题:Java JOptionPane.createDialog方法的具体用法?Java JOptionPane.createDialog怎么用?Java JOptionPane.createDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JOptionPane
的用法示例。
在下文中一共展示了JOptionPane.createDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: show
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/** Helper method for constructing an always-on-top modal dialog. */
private static Object show(String title, int type, Object message, Object[] options, Object initialOption) {
if (options == null) {
options = new Object[] {
"Ok"
};
initialOption = "Ok";
}
JOptionPane p = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, options, initialOption);
p.setInitialValue(initialOption);
JDialog d = p.createDialog(null, title);
p.selectInitialValue();
d.setAlwaysOnTop(true);
d.setVisible(true);
d.dispose();
return p.getValue();
}
示例2: actionPerformed
import javax.swing.JOptionPane; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
if (!isEnabled())
return;
TermOptions clonedTermOptions = termOptions.makeCopy();
TermOptionsPanel subPanel = new TermOptionsPanel();
subPanel.setTermOptions(clonedTermOptions);
JOptionPane optionPane = new JOptionPane(subPanel,
JOptionPane.PLAIN_MESSAGE,
JOptionPane.OK_CANCEL_OPTION
);
JDialog dialog = optionPane.createDialog(Terminal.this,
"NBTerm Options");
dialog.setVisible(true); // WILL BLOCK!
if (optionPane.getValue() == null)
return; // was closed at the window level
switch ((Integer) optionPane.getValue()) {
case JOptionPane.OK_OPTION:
System.out.printf("Dialog returned OK\n");
termOptions.assign(clonedTermOptions);
applyTermOptions(false);
termOptions.storeTo(prefs);
break;
case JOptionPane.CANCEL_OPTION:
System.out.printf("Dialog returned CANCEL\n");
break;
case JOptionPane.CLOSED_OPTION:
System.out.printf("Dialog returned CLOSED\n");
break;
default:
System.out.printf("Dialog returned OTHER: %s\n",
optionPane.getValue());
break;
}
}
示例3: createDialog
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/**
* Creates and returns a fresh dialog for the given frame.
*/
private JDialog createDialog(Component frame) {
Object[] buttons = new Object[] {getOkButton(), getCancelButton()};
JPanel input = new JPanel();
input.setLayout(new BorderLayout());
input.add(getChoiceBox(), BorderLayout.NORTH);
// add an error label if there is a parser
if (this.parsed) {
JPanel errorPanel = new JPanel(new BorderLayout());
errorPanel.add(getErrorLabel());
input.add(errorPanel, BorderLayout.SOUTH);
}
JPanel main = new JPanel();
main.setLayout(new BorderLayout());
main.add(input, BorderLayout.CENTER);
if (this.parsed) {
main.add(createSyntaxPanel(), BorderLayout.EAST);
}
JOptionPane panel = new JOptionPane(main, JOptionPane.PLAIN_MESSAGE,
JOptionPane.OK_CANCEL_OPTION, null, buttons);
JDialog result = panel.createDialog(frame, this.title);
result.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
result.addWindowListener(this.closeListener);
return result;
}
示例4: createDialog
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/**
* Creates and returns a fresh dialog for the given frame.
*/
private JDialog createDialog(Component frame) {
Object[] buttons = new Object[] {getOkButton(), getCancelButton()};
// input panel with text area and choice box
JPanel input = new JPanel();
input.setLayout(new BorderLayout());
input.setPreferredSize(new Dimension(300, 150));
input.add(new JLabel("<html><b>Enter value:"), BorderLayout.NORTH);
input.add(new JScrollPane(getTextArea()), BorderLayout.CENTER);
input.add(getChoiceBox(), BorderLayout.SOUTH);
JPanel main = new JPanel();
main.setLayout(new BorderLayout());
main.add(input, BorderLayout.CENTER);
if (this.parsed) {
JPanel errorPanel = new JPanel(new BorderLayout());
errorPanel.add(getErrorLabel());
main.add(errorPanel, BorderLayout.SOUTH);
main.add(createSyntaxPanel(), BorderLayout.EAST);
}
JOptionPane panel = new JOptionPane(main, JOptionPane.PLAIN_MESSAGE,
JOptionPane.OK_CANCEL_OPTION, null, buttons);
JDialog result = panel.createDialog(frame, this.title);
result.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
result.addWindowListener(this.closeListener);
return result;
}
示例5: createCancelDialog
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/**
* Creates a modal dialog that will interrupt this thread, when the
* cancel button is pressed.
*/
private JDialog createCancelDialog() {
JDialog result;
// create message dialog
JOptionPane message = new JOptionPane(
isAnimated() ? getAnimationPanel()
: new Object[] {getStateCountLabel(), getTransitionCountLabel()},
JOptionPane.PLAIN_MESSAGE);
message.setOptions(new Object[] {getCancelButton()});
result = message.createDialog(getFrame(), "Exploring state space");
result.pack();
result.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
result.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
ExploreThread.this.interrupt();
}
});
result.setAlwaysOnTop(true);
return result;
}
示例6: inputPassword
import javax.swing.JOptionPane; //导入方法依赖的package包/类
@Override
public String inputPassword(String messageText) {
final JPasswordField passwordField = new JPasswordField();
JOptionPane jop = new JOptionPane(new Object[] { messageText, passwordField }, JOptionPane.QUESTION_MESSAGE,
JOptionPane.OK_CANCEL_OPTION);
JDialog dialog = jop.createDialog("Auhtentication required");
dialog.addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
passwordField.requestFocusInWindow();
passwordField.requestFocus();
}
});
}
});
dialog.setVisible(true);
int result = (Integer) jop.getValue();
if (result == JOptionPane.OK_OPTION) {
return new String(passwordField.getPassword());
} else {
return null;
}
}
示例7: showmsg
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/**
* Popup the given informative message, then ask the user to click Close to
* close it.
*/
public static void showmsg(String title, Object... msg) {
JButton dismiss = new JButton(Util.onMac() ? "Dismiss" : "Close");
Object[] objs = new Object[msg.length + 1];
System.arraycopy(msg, 0, objs, 0, msg.length);
objs[objs.length - 1] = OurUtil.makeH(null, dismiss, null);
JOptionPane about = new JOptionPane(objs, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
new Object[] {});
JDialog dialog = about.createDialog(null, title);
dismiss.addActionListener(Runner.createDispose(dialog));
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
dialog.dispose();
}
示例8: showDialog
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/** Shows the content of this table as a dialog. */
public void showDialog(Component parent) {
JScrollPane scrollPane = new JScrollPane(this);
Dimension size = scrollPane.getPreferredSize();
size.height = getPreferredSize().height;
scrollPane.getViewport().setPreferredSize(size);
JOptionPane optionPane = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE);
JDialog dialog = optionPane.createDialog(parent, "External libraries used in GROOVE");
dialog.setVisible(true);
}
示例9: showDialog
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/** Shows the content of this table as a dialog. */
public void showDialog(Component parent, String title) {
JScrollPane scrollPane = new JScrollPane(this);
scrollPane.getViewport().setPreferredSize(getPreferredSize());
JOptionPane optionPane = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE);
JDialog dialog = optionPane.createDialog(parent, title);
dialog.setVisible(true);
}
示例10: show
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/** Shows a given graph in an optionally modal dialog. */
private void show(final Graph graph, GrammarModel grammar, boolean modal) {
GraphPreviewPanel panel = GraphPreviewDialog.createPanel(grammar, graph);
panel.add(new NodeIdsButton(panel), BorderLayout.NORTH);
JOptionPane optionPane = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE);
JDialog dialog = optionPane.createDialog(graph.getName());
dialog.setModal(modal);
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}
示例11: show
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/** Helper method for constructing an always-on-top modal dialog. */
private static Object show(String title, int type, Object message, Object[] options, Object initialOption) {
if (options == null) { options = new Object[]{"Ok"}; initialOption = "Ok"; }
JOptionPane p = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, options, initialOption);
p.setInitialValue(initialOption);
JDialog d = p.createDialog(null, title);
p.selectInitialValue();
d.setAlwaysOnTop(true);
d.setVisible(true);
d.dispose();
return p.getValue();
}
示例12: showmsg
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/** Popup the given informative message, then ask the user to click Close to close it. */
public static void showmsg(String title, Object... msg) {
JButton dismiss = new JButton(Util.onMac() ? "Dismiss" : "Close");
Object[] objs = new Object[msg.length + 1];
System.arraycopy(msg, 0, objs, 0, msg.length);
objs[objs.length - 1] = OurUtil.makeH(null, dismiss, null);
JOptionPane about = new JOptionPane(objs, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[]{});
JDialog dialog = about.createDialog(null, title);
dismiss.addActionListener(Runner.createDispose(dialog));
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
dialog.dispose();
}
示例13: toObsidianFile
import javax.swing.JOptionPane; //导入方法依赖的package包/类
@Override
public ObsidianFile toObsidianFile(File file) {
String error = "Failed to import from Tabula file: " + file.getName();
try
{
String entityName = file.getName().substring(0, file.getName().indexOf("."));
//Model
TabulaModel tblModel = new TabulaModel(file);
String duplicatePartName;
if((duplicatePartName = containsDuplicateParts(tblModel)) != null) {
error += ". The model contains the duplicate part " + duplicatePartName;
throw new RuntimeException(error);
}
ObjModel objModel = tblConverter.tcn2obj(tblModel, 0.0625f);
byte[] modelBytes = createModelBytes(objModel.toStringList());
//Texture
ZipFile zipFile = new ZipFile(file);
ZipEntry textureEntry = zipFile.getEntry(TBL_TEXTURE_NAME);
byte[] textureBytes;
if(textureEntry != null)
textureBytes = IOUtils.toByteArray(zipFile.getInputStream(textureEntry));
else {
File defaultTexture = new File(getClass().getClassLoader().getResource("model_textures/grey.png").getPath());
textureBytes = IOUtils.toByteArray(new FileInputStream(defaultTexture));
}
zipFile.close();
return new ObsidianFile(entityName, modelBytes, textureBytes);
}
catch (Exception e1)
{
final JOptionPane pane = new JOptionPane(error);
final JDialog d = pane.createDialog((JFrame)null, "Import Error");
d.setAlwaysOnTop(true);
d.setVisible(true);
e1.printStackTrace();
return null;
}
}
示例14: toObsidianFile
import javax.swing.JOptionPane; //导入方法依赖的package包/类
@Override
public ObsidianFile toObsidianFile(File file)
{
String error = "Failed to import from Qubble file: " + file.getName();
try
{
String entityName = file.getName().split("\\.")[0];
//Model
QubbleModel qubbleModel = load(file);
String duplicatePartName;
if((duplicatePartName = containsDuplicateParts(qubbleModel)) != null) {
error += ". The model contains the duplicate part " + duplicatePartName;
throw new RuntimeException(error);
}
ObjModel objModel = qblConverter.qbl2obj(qubbleModel, 0.0625F);
//Texture
ZipFile zipFile = new ZipFile(file);
ZipEntry textureEntry = zipFile.getEntry("base.png");
byte[] textureBytes;
if (textureEntry != null)
{
textureBytes = IOUtils.toByteArray(zipFile.getInputStream(textureEntry));
}
else
{
textureBytes = IOUtils.toByteArray(new FileInputStream(defaultTexture));
}
zipFile.close();
byte[] modelBytes = createModelBytes(objModel.toStringList());
return new ObsidianFile(entityName, modelBytes, textureBytes);
}
catch (Exception e1)
{
final JOptionPane pane = new JOptionPane(error);
final JDialog d = pane.createDialog(null, "Import Error");
d.setAlwaysOnTop(true);
d.setVisible(true);
e1.printStackTrace();
return null;
}
}
示例15: readFromGUI
import javax.swing.JOptionPane; //导入方法依赖的package包/类
/**
* Ask using a GUI for the username and password.
*/
private void readFromGUI() {
// Create fields for user name.
final JTextField usernameField = new JTextField(20);
usernameField.setText(this.username);
final JLabel usernameLabel = new JLabel("Username: ");
usernameLabel.setLabelFor(usernameField);
final JPanel usernamePane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
usernamePane.add(usernameLabel);
usernamePane.add(usernameField);
// Create fields for password.
final JPasswordField passwordField = new JPasswordField(20);
passwordField.setText(this.password);
final JLabel passwordLabel = new JLabel("Password: ");
passwordLabel.setLabelFor(passwordField);
final JPanel passwordPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
passwordPane.add(passwordLabel);
passwordPane.add(passwordField);
// Create panel
final JPanel main = new JPanel();
main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));
main.add(usernamePane);
main.add(passwordPane);
// Create and handle dialog
final JOptionPane jop = new JOptionPane(main, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
final JDialog dialog = jop.createDialog("User name and password");
dialog.addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (usernameField.getText().isEmpty())
{
usernameField.requestFocusInWindow();
}
else
{
passwordField.requestFocusInWindow();
}
}
});
}
});
dialog.setVisible(true);
final Integer result = (Integer) jop.getValue();
dialog.dispose();
if (result.intValue() == JOptionPane.OK_OPTION) {
this.username = usernameField.getText();
final char[] pwd = passwordField.getPassword();
this.password = new String(pwd);
}
}