List of usage examples for javax.swing JDialog setVisible
public void setVisible(boolean b)
From source file:Main.java
public static void showDialog(JDialog d) { 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);/*w w w .j a v a 2 s . c o m*/ d.setVisible(true); }
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
private static void installCallback(JFrame frame, File selected) { JDialog dialog = new JDialog(frame); JLabel status = new JLabel("Downloading build..."); JProgressBar progress = new JProgressBar(); dialog.pack();//from w w w . j a va 2s. c o m dialog.setVisible(true); try { URL url = new URL("http://download.redstonelamp.net/?file=LatestBuild"); InputStream is = url.openStream(); int size = is.available(); progress.setMinimum(0); progress.setMaximum(size); int size2 = size; OutputStream os = new FileOutputStream(new File(selected, "RedstoneLamp.jar")); while (size2 > 0) { int length = Math.min(4096, size2); byte[] buffer = new byte[length]; size2 -= length; is.read(buffer); progress.setValue(size2); os.write(buffer); } is.close(); os.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:eu.delving.sip.base.VisualFeedback.java
public static boolean askOption(JDesktopPane desktop, Object message, String title, int optionType, int messageType) { JOptionPane pane = new JOptionPane(message, messageType, optionType, null, null, null); pane.putClientProperty(new Object(), Boolean.TRUE); JDialog frame = pane.createDialog(desktop, title); pane.selectInitialValue();/*from w w w . j a v a 2 s . c o m*/ frame.setVisible(true); acquireFocus(); Object selectedValue = pane.getValue(); return selectedValue != null && selectedValue instanceof Integer && (Integer) selectedValue == YES_OPTION; }
From source file:eu.delving.sip.base.VisualFeedback.java
public static String askQuestion(JDesktopPane desktop, String question, Object initialSelectionValue) { final JOptionPane pane = new JOptionPane(question, QUESTION_MESSAGE, OK_CANCEL_OPTION, null, null, null); pane.putClientProperty(new Object(), Boolean.TRUE); pane.setWantsInput(true);//from w w w . jav a 2 s . c o m pane.setInitialSelectionValue(initialSelectionValue); JDialog frame = pane.createDialog(desktop, "Question"); pane.selectInitialValue(); frame.setVisible(true); acquireFocus(); Object value = pane.getInputValue(); return value == UNINITIALIZED_VALUE ? null : (String) value; }
From source file:Main.java
static public JDialog addDialogWindow(Frame mainWindow, Component jpanel, String title) { JDialog dialog = new JDialog(mainWindow, title, true); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(jpanel, BorderLayout.CENTER); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.pack();/*from w w w .j a v a 2 s .c om*/ dialog.setLocationRelativeTo(mainWindow); dialog.setSize(jpanel.getPreferredSize()); dialog.setVisible(true); return dialog; }
From source file:Main.java
/** * Binds an action to the dialog so when the user presses the ESCAPE key, the dialog is hidden. * /* w w w . j a v a 2 s .co m*/ * @param dialog * the dialog to bind the action to. */ public static void bindEscapeAction(final JDialog dialog) { InputMap iMap = dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape"); ActionMap aMap = dialog.getRootPane().getActionMap(); aMap.put("escape", new AbstractAction() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }); }
From source file:net.menthor.editor.v2.util.Util.java
/** Helper method for constructing an always-on-top modal dialog. */ public static Object show(String title, int type, Object message, Object[] options, Object initialOption) { if (options == null) { options = new Object[] { "Ok" }; initialOption = "Ok"; }/*ww w.j a va2 s . co m*/ 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(); }
From source file:Main.java
public static void openDialogNextToParent(final JComponent parentComponent, final JDialog dialog) { SwingUtilities.invokeLater(new Runnable() { @Override//from ww w.ja va 2 s.co m public void run() { if (parentComponent != null) { Point parentLocation = parentComponent.getLocationOnScreen(); parentLocation.x += parentComponent.getWidth(); dialog.setLocation(parentLocation); } dialog.setVisible(true); dialog.setSize(dialog.getPreferredSize()); } }); }
From source file:Main.java
static public JDialog addModelessWindow(Frame mainWindow, Component jpanel, String title) { JDialog dialog = new JDialog(mainWindow, title, true); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(jpanel, BorderLayout.CENTER); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.pack();/*from w w w . ja v a 2 s. c om*/ dialog.setLocationRelativeTo(mainWindow); dialog.setModalityType(ModalityType.MODELESS); dialog.setSize(jpanel.getPreferredSize()); dialog.setVisible(true); return dialog; }
From source file:Main.java
/** * Creates an animation to fade the dialog opacity from 0 to 1. *///from w w w . ja v a2 s .co m public static void fadeIn(final JDialog dialog) { final Timer timer = new Timer(10, null); timer.setRepeats(true); timer.addActionListener(new ActionListener() { private float opacity = 0; @Override public void actionPerformed(ActionEvent e) { opacity += 0.15f; dialog.setOpacity(Math.min(opacity, 1)); if (opacity >= 1) timer.stop(); } }); dialog.setOpacity(0); timer.start(); dialog.setVisible(true); }