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); progressBar.setIndeterminate(true); 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);
setTitle("Quiz"); setContentPane(optionPane); setDefaultCloseOperation(DISPOSE_ON_CLOSE); optionPane.addPropertyChangeListener(this); pack(); dispose(); @Override public void run() { new CustomDialog(null, "David").setVisible(true);
Dialog dialog = new Dialog(Activity.this); dialog.setContentView(R.layout.list) ListView lv = (ListView ) dialog.findViewById(R.id.lv); dialog.setCancelable(true); dialog.setTitle("ListView"); dialog.show();
Dialog dialog = new Dialog(this, R.style.PauseDialog); // Setting the title and layout for the dialog dialog.setTitle(R.string.pause_menu_label); dialog.setContentView(R.layout.pause_menu);
final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.custom_dialog); dialog.setTitle("Custom Alert Dialog"); final EditText editText = (EditText) dialog.findViewById(R.id.editText); Button btnSave = (Button) dialog.findViewById(R.id.save); Button btnCancel = (Button) dialog.findViewById(R.id.cancel); dialog.show();
private JDialog dialog = new JDialog(); private BackgroundPanel panel = new BackgroundPanel(); getScreenInsets(dialog.getGraphicsConfiguration()); int taskBarSize = scnMax.bottom; panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.NORTH; JButton b = new JButton(new AbstractAction("x") { dialog.dispose(); b.setMargin(new Insets(1, 4, 1, 4)); b.setFocusable(false); panel.add(b, constraints); dialog.setUndecorated(true); dialog.setSize(300, 100); dialog.setLocation(screenSize.width - dialog.getWidth(), screenSize.height - taskBarSize - dialog.getHeight()); lpg = new LinearGradientPaint(0, 0, 0, dialog.getHeight() / 2, new float[]{0f, 0.3f, 1f}, new Color[]{new Color(0.8f, 0.8f, 1f), new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f)}); dialog.setContentPane(panel); dialog.setVisible(true);
final JDialog emailDialog = new JDialog(frame); emailDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); emailDialog.setLayout(new BorderLayout()); JButton sendMailBtn = new JButton("Send Email"); sendMailBtn.addActionListener(new ActionListener() { emailDialog.dispose(); final JDialog emailProgressDialog = new JDialog(frame); emailProgressDialog.add(new JLabel("Mail in progress")); emailProgressDialog.pack(); emailProgressDialog.setVisible(true); emailDialog.add(sendMailBtn, BorderLayout.SOUTH); emailDialog.pack(); JButton openDialog = new JButton("Open emailDialog"); openDialog.addActionListener(new ActionListener() { emailDialog.setVisible(true); frame.getContentPane().add(openDialog);
JFrame frame = new JFrame("DialogClosing"); mainPanel.add(new JButton(new MyAction(frame, JDialog.DISPOSE_ON_CLOSE, "DISPOSE_ON_CLOSE"))); mainPanel.add(new JButton(new MyAction(frame, JDialog.HIDE_ON_CLOSE, "HIDE_ON_CLOSE"))); mainPanel.add(new JButton(new MyAction(frame, JDialog.DO_NOTHING_ON_CLOSE, "DO_NOTHING_ON_CLOSE"))); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); dialog = new JDialog(frame, title, false); dialog.setDefaultCloseOperation(defaultCloseOp); dialog.setPreferredSize(new Dimension(300, 200)); dialog.pack(); dialog.setVisible(true);
editorComponent = new JButton(); editorComponent.setBackground(Color.white); editorComponent.setBorderPainted(false); popup.setLocation(p.x, p.y + editorComponent.getSize().height); popup.show(); fireEditingStopped(); textArea.getInputMap().put(keyStroke, "none"); JScrollPane scrollPane = new JScrollPane( textArea ); getContentPane().add( scrollPane ); JButton cancel = new JButton("Cancel"); cancel.addActionListener( this ); JButton ok = new JButton("Ok"); ok.setPreferredSize( cancel.getPreferredSize() ); ok.addActionListener( this ); buttons.add( ok ); buttons.add( cancel ); getContentPane().add(buttons, BorderLayout.SOUTH); pack(); getRootPane().setDefaultButton( ok ); setVisible( false ); table.getColumnModel().getColumn(1).setCellEditor( popupEditor );
JButton btn = new JButton(" Save changes "); btn.addActionListener(new ActionListener() { dialog.setVisible(false); dialog.setVisible(false); dialog = new JDialog(); dialog.add(btn); dialog.add(btn1); dialog.setVisible(false); dialog.setAlwaysOnTop(true); dialog.setModal(true); dialog.setLayout(new GridLayout(2, 0, 10, 10)); JPanel pane = (JPanel) dialog.getContentPane(); if (confirm == 0) { dialog.setVisible(true); } else if (confirm == 1) {// nothing only hide JDialog dialog.setVisible(true); dialog.setVisible(false); location = frame.getLocationOnScreen(); int x = location.x; dialog.setVisible(true);
@Override public void run() { JFrame frame = new JFrame(); JButton button = new JButton(); button.addActionListener(new ActionListener() { @Override frame.getContentPane().add(button); frame.pack(); frame.setVisible(true); private JFrame frame = new JFrame(); private JDialog dialog = new JDialog(frame, "Swingworker test", true); private JProgressBar progressBar = new JProgressBar(); progressBar.setStringPainted(true); progressBar.setIndeterminate(true); dialog.getContentPane().add(progressBar); dialog.pack(); dialog.setModal( false ); dialog.setVisible(true); System.out.println("done"); JLabel label = new JLabel("Task Complete"); dialog.getContentPane().remove(progressBar); dialog.getContentPane().add(label); dialog.getContentPane().validate();
import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.GroupLayout;import javax.swing.GroupLayout.Alignment;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.LayoutStyle.ComponentPlacement;import javax.swing.border.EmptyBorder;import javax.swing.filechooser.FileFilter;import javax.swing.filechooser.FileNameExtensionFilter;public class ConfigureDialog extends JDialog implements ActionListener{private static final long serialVersionUID=1L;private final JPanel contentPanel=new JPanel();private JTextField driverPathTextField;private JLabel lblDriverPath;private JButton btnBrowse;public static void main(String[]args){try{ConfigureDialog dialog=new ConfigureDialog(new JFrame());dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);dialog.setVisible(true);}catch(Exception e){e.printStackTrace();}} public ConfigureDialog(JFrame parent){super(parent,"",true);if(parent!=null){Dimension parentSize=parent.getSize();Point p=parent.getLocation();setLocation(p.x+parentSize.width+100,p.y+parentSize.height/1);} setBounds(100,100,479,141);getContentPane().setLayout(new BorderLayout());contentPanel.setBorder(new EmptyBorder(5,5,5,5));getContentPane().add(contentPanel,BorderLayout.CENTER);{lblDriverPath=new JLabel("Driver Path : ");} {driverPathTextField=new JTextField(System.getProperty("web.ie.driver"));driverPathTextField.setColumns(10);} btnBrowse=new JButton("Browse");GroupLayout gl_contentPanel=new GroupLayout(contentPanel);gl_contentPanel.setHorizontalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addContainerGap().addComponent(lblDriverPath).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(btnBrowse).addComponent(driverPathTextField,GroupLayout.DEFAULT_SIZE,207,Short.MAX_VALUE)).addContainerGap()));gl_contentPanel.setVerticalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(5).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(driverPathTextField,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE).addComponent(lblDriverPath)).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(btnBrowse).addContainerGap(21,Short.MAX_VALUE)));contentPanel.setLayout(gl_contentPanel);{JPanel buttonPane=new JPanel();buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));getContentPane().add(buttonPane,BorderLayout.SOUTH);{JButton okButton=new JButton("OK");okButton.setActionCommand("OK");okButton.addActionListener(this);buttonPane.add(okButton);getRootPane().setDefaultButton(okButton);} {JButton cancelButton=new JButton("Cancel");cancelButton.setActionCommand("Cancel");cancelButton.addActionListener(this);buttonPane.add(cancelButton);}} btnBrowse.addActionListener(this);}@Override public void actionPerformed(ActionEvent e){if("Cancel".contains(e.getActionCommand())){dispose();}else if("Browse".contains(e.getActionCommand())){JFileChooser fileopen=new JFileChooser();FileFilter filter=new FileNameExtensionFilter("exe file","exe");fileopen.addChoosableFileFilter(filter);fileopen.setAcceptAllFileFilterUsed(false);fileopen.setFileFilter(filter);fileopen.setFileSelectionMode(JFileChooser.FILES_ONLY);int ret=fileopen.showOpenDialog(this);if(ret==JFileChooser.APPROVE_OPTION){File file=fileopen.getSelectedFile();System.out.println(file);driverPathTextField.setText(file.getPath());}}else if("OK".contains(e.getActionCommand())){System.setProperty("web.ie.driver",driverPathTextField.getText());dispose();}}}
private JButton showDialogBtn = new JButton("Show Dialog"); private MyDialog2 myDialog = new MyDialog2(this, "My Dialog"); public void actionPerformed(ActionEvent arg0) { if (!myDialog.isVisible()) { myDialog.setVisible(true); panel.add(textField); panel.add(showDialogBtn); add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); private JButton confirmBtn = new JButton("Confirm"); String text = textfield.getText(); if (isTextValid(text)) { MyDialog2.this.setVisible(false); } else {
import java.awt.event.*; import javax.swing.*; public class TestSwing { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Parent"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800, 600); frame.setVisible(true); final JDialog dialog = new JDialog(frame, "Child", true); dialog.setSize(300, 200); dialog.setLocationRelativeTo(frame); JButton button = new JButton("Button"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); dialog.add(button); dialog.setUndecorated(true); dialog.setVisible(true); } }
super(owner); JPanel pnl = new JPanel(new BorderLayout()); pnl.add(new JLabel("Click outside this dialog in the parent frame to close it"), BorderLayout.NORTH); JButton btn = new JButton("Click Me"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pnl.add(btn, BorderLayout.CENTER); this.setContentPane(pnl); this.pack(); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setLocationRelativeTo(owner); this.setAlwaysOnTop(true); this.addWindowFocusListener(new WindowFocusListener() { return; ClickAwayDialog.this.setVisible(false); SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame parent = new JFrame(); parent.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); parent.setSize(300, 300); parent.setLocationByPlatform(true); parent.setVisible(true); ClickAwayDialog dlg = new ClickAwayDialog(parent); dlg.setVisible(true);
JFrame frame = new JFrame("Title"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(pane); frame.pack(); frame.setVisible(true); pane.add(newLabel(labelText)); pane.add(newButton("Open dialog"), BorderLayout.SOUTH); return pane; final JButton button = new JButton(label); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Window parentWindow = SwingUtilities.windowForComponent(button); JDialog dialog = new JDialog(parentWindow); dialog.setLocationRelativeTo(button); dialog.setModal(true); dialog.add(newPane("Label in dialog")); dialog.pack(); dialog.setVisible(true);
private JButton okBtn = new JButton("OK"); private JButton cancelBtn = new JButton("Cancel"); private JLabel messageLbl = new JLabel("This is a message"); super(new JFrame(), true); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setUndecorated(true); setLayout(new FlowLayout(FlowLayout.CENTER)); add(messageLbl); add(okBtn); add(cancelBtn); pack(); setLocationRelativeTo(null); setVisible(true);
import java.awt.event.*; import javax.swing.*; public class YourDialog extends JDialog implements ActionListener { JButton button; public YourDialog() { button = new JButton("Close"); button.addActionListener(this); add(button); pack(); setVisible(true); } public void actionPerformed(ActionEvent e) { dispose(); } }
private int count = TIME_OUT; private final Timer timer = new Timer(1000, this); private JDialog dialog = new JDialog(); private final JOptionPane optPane = new JOptionPane(); JFrame frame = new JFrame("Title"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); timer.setCoalesce(false); optPane.setMessage(message()); optPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); optPane.setOptionType(JOptionPane.DEFAULT_OPTION); optPane.addPropertyChangeListener(this); dialog.add(optPane); dialog.pack(); frame.add(new JLabel(frame.getTitle(), JLabel.CENTER)); frame.setVisible(true); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); timer.start(); dialog.setVisible(false); dialog.dispatchEvent(new WindowEvent( dialog, WindowEvent.WINDOW_CLOSING));
this.setLayout(new GridLayout(0, 1)); this.add(new JLabel("Dialog close test.", JLabel.CENTER)); this.add(new JButton(new AbstractAction("Close") { DialogClose.this.setVisible(false); DialogClose.this.dispatchEvent(new WindowEvent( DialogClose.this, WindowEvent.WINDOW_CLOSING)); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true);