List of usage examples for javax.swing JDialog setVisible
public void setVisible(boolean b)
From source file:Main.java
public static void main(String[] args) { String[] options = { "Button 1", "Button 2", "Button 3" }; JOptionPane myOptionPane = new JOptionPane("Heres a test message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[2]); JDialog myDialog = myOptionPane.createDialog(null, "My Test"); myDialog.setModal(true);/*from www .jav a 2 s . co m*/ inactivateOption(myDialog, options[1]); myDialog.setVisible(true); Object result = myOptionPane.getValue(); System.out.println("result: " + result); }
From source file:ApplicationModalDialogWithExcludeDemo.java
public static void main(String[] args) { final JFrame parent1 = new JFrame("Parent Frame 1"); parent1.setLayout(new FlowLayout()); parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parent1.setBounds(100, 100, 200, 150); parent1.setVisible(true);//from ww w . j av a 2 s. c o m JFrame parent2 = new JFrame("Parent Frame 2"); parent2.setBounds(500, 100, 300, 150); parent2.setVisible(true); JFrame parent3 = new JFrame("Parent Frame 3 - Excluded"); parent3.setBounds(300, 400, 300, 150); parent3.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); parent3.setVisible(true); JDialog dialog = new JDialog(parent1, "Application-Modal Dialog", Dialog.ModalityType.APPLICATION_MODAL); dialog.setBounds(300, 200, 300, 150); dialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JOptionPane jop = new JOptionPane("Message", JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION); JDialog dialog = jop.createDialog("Dialog Title"); Image image = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); dialog.setIconImage(image);/*from www. j a va 2 s . c o m*/ dialog.setVisible(true); }
From source file:CreateColorSamplePopup.java
public static void main(String args[]) { final JColorChooser colorChooser = new JColorChooser(Color.RED); ActionListener okActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Color change rejected"); }/*from w w w.ja v a2s. c o m*/ }; // For cancel selection, change button background to red ActionListener cancelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("cancled"); } }; final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true, colorChooser, okActionListener, cancelActionListener); dialog.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { final JColorChooser colorChooser = new JColorChooser(); final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER); previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); previewLabel.setSize(previewLabel.getPreferredSize()); previewLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0)); colorChooser.setPreviewPanel(previewLabel); ActionListener okActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("OK Button"); System.out.println(colorChooser.getColor()); }//ww w. ja va 2 s. c om }; ActionListener cancelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Cancel Button"); } }; final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true, colorChooser, okActionListener, cancelActionListener); dialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame1 = new JFrame(); frame1.setExtendedState(JFrame.MAXIMIZED_BOTH); frame1.setUndecorated(true);/* w ww . j ava 2s .com*/ frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.setVisible(true); JDialog nonModalDialog = new JDialog(frame1, "Non-Modal Dialog", ModalityType.MODELESS); nonModalDialog.add(Box.createRigidArea(new Dimension(200, 200))); nonModalDialog.pack(); nonModalDialog.setVisible(true); JDialog modalDialog = new JDialog(frame1, "Modal Dialog", ModalityType.APPLICATION_MODAL); modalDialog.add(Box.createRigidArea(new Dimension(200, 200))); modalDialog.pack(); modalDialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JFrame parent1 = new JFrame("Parent Frame 1"); parent1.setLayout(new FlowLayout()); parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Application modal dialog"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JDialog dialog = new JDialog(parent1, "Application-Modal Dialog", Dialog.ModalityType.APPLICATION_MODAL); dialog.setBounds(200, 150, 200, 150); dialog.setVisible(true); }//from www. j a va2s .com }); parent1.add(button); parent1.setBounds(100, 100, 200, 150); parent1.setVisible(true); JFrame parent2 = new JFrame("Parent Frame 2"); parent2.setBounds(500, 100, 200, 150); parent2.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(Main.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton("Click me to open dialog"); button.addActionListener(e -> {// ww w . jav a 2 s. c o m Window parentWindow = SwingUtilities.windowForComponent(button); JDialog dialog = new JDialog(parentWindow); dialog.setLocationRelativeTo(button); dialog.setModal(true); dialog.add(new JLabel("A dialog")); dialog.pack(); dialog.setVisible(true); }); frame.add(button); frame.pack(); frame.setVisible(true); }
From source file:DualModal.java
public static void main(String args[]) { final JFrame frame1 = new JFrame("Left"); final JFrame frame2 = new JFrame("Right"); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Left"); JButton button2 = new JButton("Right"); frame1.add(button1);//from w w w .j a va 2 s . c om frame2.add(button2); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { JButton source = (JButton) e.getSource(); JOptionPane pane = new JOptionPane("New label", JOptionPane.QUESTION_MESSAGE); pane.setWantsInput(true); JDialog dialog = pane.createDialog(frame2, "Enter Text"); // dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL); dialog.setVisible(true); String text = (String) pane.getInputValue(); if (!JOptionPane.UNINITIALIZED_VALUE.equals(text) && text.trim().length() > 0) { source.setText(text); } } }; button1.addActionListener(listener); button2.addActionListener(listener); frame1.setBounds(100, 100, 200, 200); frame1.setVisible(true); frame2.setBounds(400, 100, 200, 200); frame2.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { final JColorChooser colorChooser = new JColorChooser(); SystemColorChooserPanel newChooser = new SystemColorChooserPanel(); colorChooser.addChooserPanel(newChooser); ActionListener okActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(colorChooser.getColor()); }/*w w w. j ava 2 s .c o m*/ }; ActionListener cancelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Cancel"); } }; final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true, colorChooser, okActionListener, cancelActionListener); dialog.setVisible(true); }