private void initAboutBox() { aboutBox = new JDialog(this, "About Tregex"); aboutBox.getContentPane().setLayout(new BorderLayout()); aboutBox.getContentPane().add(new JLabel("<html><b>Tregex and Tsurgeon</b></html>", SwingConstants.CENTER), BorderLayout.NORTH); aboutBox.getContentPane().add(new JLabel("<html>Tregex by Galen Andrew and Roger Levy<br>Tsurgeon by Roger Levy<br>Graphical interface by Anna Rafferty<br>Additional features and development by Chris Manning<br></html>", SwingConstants.CENTER), BorderLayout.CENTER); aboutBox.getContentPane().add(new JLabel("<html><font size=2>\u00A92007 The Board of Trustees of The Leland Stanford Junior University.<br>Distributed under the GNU General Public License</font></html>", SwingConstants.CENTER), BorderLayout.SOUTH); }
final JDialog d = new JDialog(); d.setSize(200,200); d.setLocationRelativeTo(null); d.setVisible(true);
regionSelectDialog = new JDialog(editor, "Pick regions", true); regionPickerPanel = new RegionPickerPanel(this); JScrollPane scrollPane = new JScrollPane(); regionSelectDialog.setDefaultCloseOperation( JDialog.HIDE_ON_CLOSE); addContent(0, 0, pickButton = new JButton("Pick Regions"), false, GridBagConstraints.WEST, GridBagConstraints.NONE);
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; }
JButton showWaitBtn = new JButton(new ShowWaitAction("Show Wait Dialog")); JPanel panel = new JPanel(); panel.add(showWaitBtn); JFrame frame = new JFrame("Frame"); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); final JDialog dialog = new JDialog(win, "Dialog", ModalityType.APPLICATION_MODAL); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Please wait......."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setLocationRelativeTo(win); dialog.setVisible(true);
public ConferenceCFPImportWorker(SolutionBusiness<ConferenceSolution> solutionBusiness, SolutionPanel<ConferenceSolution> solutionPanel, String conferenceBaseUrl) { this.solutionBusiness = solutionBusiness; this.solutionPanel = solutionPanel; this.conferenceBaseUrl = conferenceBaseUrl; dialog = new JDialog(solutionPanel.getSolverAndPersistenceFrame(), true); JPanel contentPane = new JPanel(new BorderLayout(10, 10)); contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); contentPane.add(new JLabel("Importing CFP data in progress..."), BorderLayout.NORTH); JProgressBar progressBar = new JProgressBar(SwingConstants.HORIZONTAL); progressBar.setIndeterminate(true); contentPane.add(progressBar, BorderLayout.CENTER); JButton button = new JButton("Cancel"); button.addActionListener(e -> cancel(false)); contentPane.add(button, BorderLayout.SOUTH); dialog.setContentPane(contentPane); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { cancel(false); } }); dialog.pack(); dialog.setLocationRelativeTo(solutionPanel.getSolverAndPersistenceFrame()); }
final JDialog dialog = new JDialog(frame, "Jar File Chooser", true); dialog.setLocation(location); final JList fileList = new JList(new Vector<>(files)); JButton okay = new javax.swing.JButton(); okay.setText("Okay"); okay.setToolTipText("Okay"); okay.addActionListener(evt -> dialog.setVisible(false)); JButton cancel = new javax.swing.JButton(); cancel.setText("Cancel"); cancel.setToolTipText("Cancel"); cancel.addActionListener(evt -> { fileList.clearSelection(); dialog.setVisible(false); }); dialog.pack(); dialog.setSize(dialog.getPreferredSize()); dialog.setVisible(true);
import javax.swing.*; import java.awt.*; public class t { public static void main(String[] args) { JDialog downloadingDialog = new JDialog((JFrame)null ,"Start donwloading..."); JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL); progressBar.setIndeterminate(true); downloadingDialog.setLayout(new FlowLayout(FlowLayout.LEFT)); downloadingDialog.add(progressBar); downloadingDialog.setSize(300, 100); downloadingDialog.setVisible(true); } }
import javax.swing.*; class CenterTheDialog { CenterTheDialog() { for (int ii=1; ii<4; ii++) { JFrame f = new JFrame("Frame " + ii); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setSize(400,300); f.setLocationByPlatform(true); f.setVisible(true); JDialog d = new JDialog(f); d.setSize(300,200); d.setLocationRelativeTo(f); d.setVisible(true); } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new CenterTheDialog(); } }); } }
import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Test { public static void main(String[] args) { JFrame f = new JFrame(); final JDialog dialog = new JDialog(f, "Test", true); Timer timer = new Timer(2000, new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); dialog.dispose(); } }); timer.setRepeats(false); timer.start(); dialog.setVisible(true); // if modal, application will pause here System.out.println("Dialog closed"); } }
import javax.swing.JDialog; import javax.swing.JFrame; public class DialogAndDaemons { public static void main(String[] args) { JFrame frame = new JFrame(); JDialog dialog = new JDialog(frame, "Dialog"); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } }
public VUMeterMonitor() { vumeter = new VUMeter(); vuMeterPanel = new VUMeterPanel(); vuMeterPanel.setVu(vumeter); vuMeterPanel.start(); vuMeterDialog = new JDialog(); vuMeterDialog.setBounds(100, 100, 100, 400); vuMeterDialog.getContentPane().setLayout(new BorderLayout()); vuMeterDialog.getContentPane().add(vuMeterPanel); vuMeterDialog.setVisible(true); }
frame.getContentPane().add(new MyFramePanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); private JButton openDialogeBtn = new JButton("Open Dialog"); field.setFocusable(false); add(field); add(openDialogeBtn); Window win = SwingUtilities.getWindowAncestor(this); if (win != null) { dialog = new JDialog(win, "My Dialog", ModalityType.APPLICATION_MODAL); dialog.getContentPane().add(dialogPanel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); // here the modal dialog takes over private JButton okButton = new JButton("OK");
private JDialog createDialog() { dialog = new JDialog(Cytoscape.getDesktop(), "Select Nodes By Name", false); JPanel main_panel = new JPanel(); main_panel.setLayout(new BorderLayout()); JLabel label = new JLabel("<HTML>Select nodes whose <B>name or synonym</B> is like <small>(use \"*\" and \"?\" for wildcards)</small></HTML>"); main_panel.add(label, BorderLayout.NORTH); searchField = new JTextField(30); searchField.addActionListener(this); main_panel.add(searchField, BorderLayout.CENTER); JPanel button_panel = new JPanel(); search = new JButton("Search"); cancel = new JButton("Cancel"); search.addActionListener(this); cancel.addActionListener(this); button_panel.add(search); button_panel.add(cancel); main_panel.add(button_panel, BorderLayout.SOUTH); dialog.setContentPane(main_panel); dialog.pack(); return dialog; }
JButton cancel = new javax.swing.JButton(); JDialog dialog = new JDialog(new Frame(), "Parser Progress", true); dialog.setVisible(true);
regionSelectDialog = new JDialog(editor, "Pick regions", true); regionPickerPanel = new RegionPickerPanel(this); JScrollPane scrollPane = new JScrollPane(); regionSelectDialog.setDefaultCloseOperation( JDialog.HIDE_ON_CLOSE); addContent(0, 0, pickButton = new JButton("Pick Regions"), false, GridBagConstraints.WEST, GridBagConstraints.NONE);
dialog = new javax.swing.JDialog(parentDlg, title, true); } else { dialog = new javax.swing.JDialog(frame, title, true); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(chooser, BorderLayout.CENTER);
final JDialog d = new JDialog(); d.setSize(200, 200); final Toolkit toolkit = Toolkit.getDefaultToolkit(); final Dimension screenSize = toolkit.getScreenSize(); final int x = (screenSize.width - d.getWidth()) / 2; final int y = (screenSize.height - d.getHeight()) / 2; d.setLocation(x, y); d.setVisible(true);
import java.awt.event.*; import javax.swing.*; public class DialogListener { public static void main(String[] args) { JDialog dialog = new JDialog(); dialog.setSize(300, 400); dialog.setVisible(true); KeyListener listener = getKeyListener(); dialog.addKeyListener(listener); JTextArea area = new JTextArea(); area.addKeyListener(listener); dialog.add(area); } public static KeyListener getKeyListener(){ return new KeyAdapter() { public void keyTyped(KeyEvent e) { System.out.println(e.getKeyChar()); } }; } }
import javax.swing.*; class TestDialogMinimize { public static void main(String[] args) { Runnable r = new Runnable() { public void run() { JFrame f = new JFrame("Has a Dialog"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(400,400); JDialog d = new JDialog(f); d.setSize(200,200); f.setVisible(true); d.setVisible(true); } }; SwingUtilities.invokeLater(r); } }