下面列出了javax.swing.JDialog#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static JDialog createInformationDialog(final JComponent component, final String title) {
final JDialog dialog = new JDialog((JFrame) null, title);
dialog.add(component, BorderLayout.CENTER);
final JPanel buttons = new JPanel();
final JButton button =
new JButton(
SwingAction.of(
"OK",
event -> {
dialog.setVisible(false);
dialog.removeAll();
dialog.dispose();
}));
buttons.add(button);
dialog.getRootPane().setDefaultButton(button);
dialog.add(buttons, BorderLayout.SOUTH);
dialog.pack();
dialog.addWindowListener(
new WindowAdapter() {
@Override
public void windowOpened(final WindowEvent e) {
button.requestFocus();
}
});
return dialog;
}
/**
* Show a popup window with given message.
*
* @param frame Parent window
* @param panel Content in panel
* @param title Popup window title
*/
public static void showPopup(final JFrame frame, final JPanel panel, final String title) {
if (frame == null || panel == null) {
return;
}
final JDialog popup = new JDialog(frame, title);
popup.setSize(
(int) Math.floor(frame.getWidth() * POPUP_RATIO),
(int) Math.floor(frame.getHeight() * POPUP_RATIO));
popup.setLayout(new BorderLayout());
popup.add(panel, BorderLayout.CENTER);
popup.setLocationRelativeTo(frame);
popup.setVisible(true);
}
public void open() {
myDialog = new JDialog(Wandora.getWandora(), true);
myDialog.add(this);
myDialog.setSize(600,320);
myDialog.setTitle("Similarity matrix export options");
UIBox.centerWindow(myDialog, Wandora.getWandora());
wasAccepted = false;
myDialog.setVisible(true);
}
private void customizeBorderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customizeBorderActionPerformed
BorderEditor editor = new BorderEditor(currentBorder, resources);
JDialog dialog = new JDialog((JDialog)SwingUtilities.windowForComponent(this), "Border");
dialog.setLayout(new BorderLayout());
dialog.add(BorderLayout.CENTER, editor);
dialog.pack();
dialog.setLocationRelativeTo(customizeBorder);
dialog.setModal(true);
dialog.setVisible(true);
currentBorder = editor.getResult();
updateThemePreview();
}
public void openInDialog(Wandora wandora) {
setLanguages();
accepted = false;
dialog = new JDialog(wandora, true);
dialog.setSize(500,350);
dialog.setTitle("Select translation languages");
wandora.centerWindow(dialog);
dialog.add(this);
dialog.setVisible(true);
}
private void openImageInDialog( long imageId, String imageName, File dbFile, boolean doOriginalSize ) throws Exception {
BufferedImage bufferedImage = readImageToBufferedImage(imageId, dbFile, doOriginalSize);
if (bufferedImage != null) {
JDialog f = new JDialog();
f.add(new JLabel(new ImageIcon(bufferedImage)), BorderLayout.CENTER);
f.setTitle(imageName);
f.pack();
f.setSize(bufferedImage.getWidth(), bufferedImage.getHeight());
f.setLocationRelativeTo(null); // Center on screen
f.setVisible(true);
f.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
}
private static void createAndShowTestDialog(String description,
String failMessage, Runnable action) {
final JDialog dialog = new JDialog();
dialog.setTitle("Test: " + (++testCount));
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
JTextArea textArea = new JTextArea(description);
textArea.setEditable(false);
final JButton testButton = new JButton("Print Table");
final JButton passButton = new JButton("PASS");
passButton.setEnabled(false);
passButton.addActionListener((e) -> {
dialog.dispose();
});
final JButton failButton = new JButton("FAIL");
failButton.setEnabled(false);
failButton.addActionListener((e) -> {
throw new RuntimeException(failMessage);
});
testButton.addActionListener((e) -> {
testButton.setEnabled(false);
action.run();
passButton.setEnabled(true);
failButton.setEnabled(true);
});
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(textArea, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(testButton);
buttonPanel.add(passButton);
buttonPanel.add(failButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
dialog.add(mainPanel);
dialog.pack();
dialog.setVisible(true);
}
public void openInDialog(Wandora wandora) {
someLangs = filterLangs(wandora.getTopicMap(), langs);
setLanguages();
accepted = false;
dialog = new JDialog(wandora, true);
dialog.setSize(500,470);
dialog.setTitle("Select source and target languages");
wandora.centerWindow(dialog);
dialog.add(this);
dialog.setVisible(true);
}
@Override
public JDialog create(Window owner, String title, int width, int height) {
dialog = new JDialog(owner, title, Dialog.ModalityType.APPLICATION_MODAL);
dialog.add(content());
dialog.setSize(new Dimension(width, height));
dialog.setLocationRelativeTo(owner);
dialog.getContentPane().setBackground(prefs.getColorTheme().getBackgroundColor());
return dialog;
}
private static void createAndShowTestDialog(String description,
String failMessage, Runnable action) {
final JDialog dialog = new JDialog();
dialog.setTitle("Test: " + (++testCount));
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
JTextArea textArea = new JTextArea(description);
textArea.setEditable(false);
final JButton testButton = new JButton("Print Table");
final JButton passButton = new JButton("PASS");
passButton.setEnabled(false);
passButton.addActionListener((e) -> {
dialog.dispose();
});
final JButton failButton = new JButton("FAIL");
failButton.setEnabled(false);
failButton.addActionListener((e) -> {
throw new RuntimeException(failMessage);
});
testButton.addActionListener((e) -> {
testButton.setEnabled(false);
action.run();
passButton.setEnabled(true);
failButton.setEnabled(true);
});
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(textArea, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(testButton);
buttonPanel.add(passButton);
buttonPanel.add(failButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
dialog.add(mainPanel);
dialog.pack();
dialog.setVisible(true);
}
public void open(Wandora w) {
accepted = false;
dialog = new JDialog(w, true);
dialog.setSize(750,400);
dialog.add(this);
dialog.setTitle("SQL Extractor");
UIBox.centerWindow(dialog, w);
dialog.setVisible(true);
}
private void openOptionsDialog() {
optionsDialog = new JDialog(Wandora.getWandora(), true);
optionsDialog.setSize(500,270);
optionsDialog.add(optionsPanel);
optionsDialog.setTitle("R topic panel options");
Wandora.getWandora().centerWindow(optionsDialog);
optionsDialog.setVisible(true);
}
void open() {
app = Wandora.getWandora();
window = new JDialog(app, AbstractFBGraphExtractor.NAME, true);
window.add(this);
window.setSize(DIMENSION);
app.centerWindow(window);
window.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
JDialog dlg = new JDialog(((Main) PacketSamurai.getUserInterface()).getMainFrame(), "Text");
dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dlg.setSize(350, 400);
dlg.setLocationRelativeTo(((Main) PacketSamurai.getUserInterface()).getMainFrame());
JEditorPane sourceDisplay = new JEditorPane();
sourceDisplay.setEditable(false);
sourceDisplay.setContentType("text/plain");
sourceDisplay.setText(_xml);
dlg.add(new JScrollPane(sourceDisplay));
dlg.setVisible(true);
}
@Override
protected JDialog initDialog(Window owner, Object constraints) {
JDialog ret = new JDialog(owner, ModalityType.APPLICATION_MODAL);
ret.setLayout(new BorderLayout());
ret.setResizable(false);
ret.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
ret.setTitle(Messages.get("term.aboutApp"));
ret.add(pnl, BorderLayout.CENTER);
ret.pack();
return ret;
}
@Override
public JDialog create(Window owner, String title, int width, int height) {
dialog = new JDialog(owner, title, Dialog.ModalityType.APPLICATION_MODAL);
dialog.add(content());
dialog.setSize(new Dimension(width, height));
dialog.setLocationRelativeTo(owner);
dialog.getContentPane().setBackground(prefs.getColorTheme().getBackgroundColor());
return dialog;
}
@Override
public JDialog getDialog(ApplicationFrame frame) {
JDialog dialog = new JDialog(frame, "About Configurator", true);
dialog.setBackground(Color.WHITE);
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dialog.setResizable(false);
dialog.add(new JLabel("Void Frame"));
dialog.pack();
dialog.setVisible(false);
return dialog;
}
@Override
public JDialog create(Window owner, String title, int width, int height) {
dialog = new JDialog(owner, title, Dialog.ModalityType.APPLICATION_MODAL);
dialog.add(content());
dialog.setSize(new Dimension(width, height));
dialog.setLocationRelativeTo(owner);
dialog.getContentPane().setBackground(prefs.getColorTheme().getBackgroundColor());
return dialog;
}
private static void doTest(Runnable action) {
String description
= " A print dialog would appear.\n"
+ " Increase the no. of copies.\n"
+ " If COLLATE checkbox gets enabled, press FAIL else press PASS.\n"
+ " Press Cancel to close the dialog.";
final JDialog dialog = new JDialog();
dialog.setTitle("printSelectionTest");
JTextArea textArea = new JTextArea(description);
textArea.setEditable(false);
final JButton testButton = new JButton("Start Test");
final JButton passButton = new JButton("PASS");
passButton.setEnabled(false);
passButton.addActionListener((e) -> {
dialog.dispose();
pass();
});
final JButton failButton = new JButton("FAIL");
failButton.setEnabled(false);
failButton.addActionListener((e) -> {
dialog.dispose();
fail();
});
testButton.addActionListener((e) -> {
testButton.setEnabled(false);
action.run();
passButton.setEnabled(true);
failButton.setEnabled(true);
});
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(textArea, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(testButton);
buttonPanel.add(passButton);
buttonPanel.add(failButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
dialog.add(mainPanel);
dialog.pack();
dialog.setVisible(true);
}
private static void doTest(Runnable action) {
String description
= " Visual inspection of print dialog is required.\n"
+ " A print dialog will be shown.\n "
+ " Please verify Copies 5 is selected.\n"
+ " Also verify, Page Range is selected with "
+ " from page 3 and to Page 4.\n"
+ " If ok, press PASS else press FAIL";
final JDialog dialog = new JDialog();
dialog.setTitle("printSelectionTest");
JTextArea textArea = new JTextArea(description);
textArea.setEditable(false);
final JButton testButton = new JButton("Start Test");
final JButton passButton = new JButton("PASS");
passButton.setEnabled(false);
passButton.addActionListener((e) -> {
dialog.dispose();
pass();
});
final JButton failButton = new JButton("FAIL");
failButton.setEnabled(false);
failButton.addActionListener((e) -> {
dialog.dispose();
fail();
});
testButton.addActionListener((e) -> {
testButton.setEnabled(false);
action.run();
passButton.setEnabled(true);
failButton.setEnabled(true);
});
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(textArea, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(testButton);
buttonPanel.add(passButton);
buttonPanel.add(failButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
dialog.add(mainPanel);
dialog.pack();
dialog.setVisible(true);
}