List of usage examples for javax.swing JOptionPane YES_NO_OPTION
int YES_NO_OPTION
To view the source code for javax.swing JOptionPane YES_NO_OPTION.
Click Source Link
showConfirmDialog
. From source file:GUI.MainJF.java
public void LlenarTabla() { String[] columnNames = { "ID", "Nombre", "Email", "Edad", "Tipo", "", "" }; Object[][] data = null;//from w w w . j a v a 2 s. com DefaultTableModel model = new DefaultTableModel(data, columnNames); HttpResponse response; response = JSON.request(Config.URL + "usuarios/listar.json"); JSONObject jObject = JSON.JSON(response); try { JSONArray jsonArr = jObject.getJSONArray("data"); for (int i = 0; i < jsonArr.length(); i++) { JSONObject data_json = jsonArr.getJSONObject(i); model.addRow( new Object[] { data_json.get("idUsuario").toString(), data_json.get("nombre").toString(), data_json.get("email").toString(), data_json.get("edad").toString(), data_json.get("descripcion").toString(), "Editar", "Eliminar" }); } } catch (Exception e) { e.printStackTrace(); } tb_usuarios.setModel(model); Action editar = new AbstractAction() { public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0); String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1); String email = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 2); String edad = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 3); String tipo = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 4); FormUsuarios U = new FormUsuarios(); U.setID(id); U.setNombre(nombre); U.setEmail(email); U.setEdad(edad); U.setTipo(tipo); U.setLocationRelativeTo(null); U.setVisible(true); } }; ButtonColumn botonEditar = new ButtonColumn(tb_usuarios, editar, 5); botonEditar.setMnemonic(KeyEvent.VK_D); Action eliminar = new AbstractAction() { public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); String id = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 0); String nombre = (String) ((DefaultTableModel) table.getModel()).getValueAt(modelRow, 1); int rs = JOptionPane.showConfirmDialog(null, "Estas seguro que deseas eliminas el usuario: " + nombre + " ?", "Eliminar", JOptionPane.YES_NO_OPTION); if (rs == JOptionPane.YES_OPTION) { List<NameValuePair> parametros = new ArrayList<NameValuePair>(); parametros.add(new BasicNameValuePair("idUsuario", id)); HttpResponse response = JSON.request(Config.URL + "usuarios/eliminar.json", parametros); JSONObject jObject = JSON.JSON(response); int code = Integer.parseInt(jObject.get("code").toString()); /*if(code == 201){ JOptionPane.showMessageDialog(null, "Usuario eliminado"); //((DefaultTableModel)table.getModel()).removeRow(modelRow); }else{ JOptionPane.showMessageDialog(null, "Error eliminar Usuario"); }*/ } } }; ButtonColumn botonEliminar = new ButtonColumn(tb_usuarios, eliminar, 6); botonEliminar.setMnemonic(KeyEvent.VK_D); model.fireTableDataChanged(); }
From source file:com.stefanbrenner.droplet.ui.actions.SaveFileAction.java
protected void showFileChooser() { int returnVal = fileChooser.showSaveDialog(getFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { // Get the selected file File file = fileChooser.getSelectedFile(); // check if file extension fits if (StringUtils.containsIgnoreCase(file.getName(), ".") //$NON-NLS-1$ && !(StringUtils.endsWithIgnoreCase(file.getName(), "." + IDropletContext.DROPLET_FILE_EXTENSION))) { JOptionPane.showMessageDialog(getFrame(), Messages.getString("SaveFileAction.extensionNotAllowed"), //$NON-NLS-1$ Messages.getString("SaveFileAction.wrongExtension"), //$NON-NLS-1$ JOptionPane.ERROR_MESSAGE); showFileChooser();// w w w . j a v a 2s .c o m return; } else { // automatically add droplet file extension if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + IDropletContext.DROPLET_FILE_EXTENSION)) { String newPath = StringUtils.join(file.getPath(), "." + IDropletContext.DROPLET_FILE_EXTENSION); file = new File(newPath); } } // check if file already exists if (file.exists()) { int retVal = JOptionPane.showConfirmDialog(getFrame(), Messages.getString("SaveFileAction.overwriteFile"), Messages.getString("SaveFileAction.1"), //$NON-NLS-1$ //$NON-NLS-2$ JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (retVal == JOptionPane.NO_OPTION) { showFileChooser(); return; } } saveFile(file); // set file to context getDropletContext().setFile(file); } }
From source file:gate.Main.java
/** Run the user interface. */ protected static void runGui() throws GateException { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); // initialise the library and load user CREOLE directories try {// w ww .ja v a 2s. c o m Gate.init(); } catch (Throwable t) { log.error("Problem while initialising GATE", t); int selection = JOptionPane.showOptionDialog(null, "Error during initialisation:\n" + t.toString() + "\nDo you still want to start GATE?", "GATE", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new String[] { "Cancel", "Start anyway" }, "Cancel"); if (selection != 1) { System.exit(1); } } //create the main frame, show it SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice().getDefaultConfiguration(); //this needs to run before any GUI component is constructed. applyUserPreferences(); //all the defaults tables have been updated; build the GUI frame = MainFrame.getInstance(gc); if (DEBUG) Out.prln("constructing GUI"); // run the GUI frame.setTitleChangable(true); frame.setTitle(name + " " + version + " build " + build); // Set title from Java properties String title = System.getProperty(GateConstants.TITLE_JAVA_PROPERTY_NAME); if (title != null) { frame.setTitle(title); } // if frame.setTitleChangable(false); // Set icon from Java properties // iconName could be absolute or "gate:/img/..." String iconName = System.getProperty(GateConstants.APP_ICON_JAVA_PROPERTY_NAME); if (iconName != null) { try { frame.setIconImage(Toolkit.getDefaultToolkit().getImage(new URL(iconName))); } catch (MalformedURLException mue) { log.warn("Could not load application icon.", mue); } } // if // Validate frames that have preset sizes frame.validate(); // Center the window Rectangle screenBounds = gc.getBounds(); Dimension screenSize = screenBounds.getSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); //load session if required and available; //do everything from a new thread. Runnable runnable = new Runnable() { @Override public void run() { try { File sessionFile = Gate.getUserSessionFile(); if (sessionFile.exists()) { MainFrame.lockGUI("Loading saved session..."); PersistenceManager.loadObjectFromFile(sessionFile); } } catch (Exception e) { log.warn("Failed to load session data", e); } finally { MainFrame.unlockGUI(); } } }; Thread thread = new Thread(Thread.currentThread().getThreadGroup(), runnable, "Session loader"); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } }); registerCreoleUrls(); }
From source file:Main_Window.java
public Main_Window() { super("Google Places Application"); //First call Constructor of JFrame this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //We do not want our application to terminate when a JFrame is closed this.addWindowListener(new java.awt.event.WindowAdapter() { @Override// w w w. j av a2 s . c o m public void windowClosing(java.awt.event.WindowEvent windowEvent) { int Answer = JOptionPane.showConfirmDialog(null, "Exit Application ? ", "Exit ? ", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (Answer == JOptionPane.YES_OPTION) { if (POI_List.isEmpty()) { POI_List.clear(); } if (Distances_List.isEmpty()) { Distances_List.clear(); } if (Temp_List.isEmpty()) { Temp_List.clear(); } if (Distances_List_2.isEmpty()) { Distances_List_2.clear(); } System.exit(1); } else { setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); } } }); //The listener object created from that class is then registered with a Window using the window's addWindowListener method. // this.setSize(1100, 700); // Size of Window this.setLocationRelativeTo(null); // Display Window in center of Screen this.setVisible(true); this.getContentPane().setBackground(Color.LIGHT_GRAY); // //Initialization of J Components POIS_Label = new JLabel("Points of Interest:"); POIS_Label.setForeground(Color.black); POIS_Label.setFont(new Font("Courier New", Font.BOLD, 25)); POIS_Label.setBounds(600, 30, 350, 150); Retrieve_POIs_Button = new JButton("Retrieve POIs"); Retrieve_POIs_Button.setForeground(Color.black); Retrieve_POIs_Button.setFont(new Font("Courier New", Font.BOLD, 35)); Retrieve_POIs_Button.setBounds(25, 450, 350, 150); Open_Status = new JRadioButton(" Open Now?"); Open_Status.setForeground(Color.black); Open_Status.setBackground(Color.LIGHT_GRAY); Open_Status.setBounds(20, 380, 100, 30); Welcome_Label = new JLabel("Welcome to Google Places"); Welcome_Label.setForeground(Color.BLUE); Welcome_Label.setFont(new Font("Courier New", Font.BOLD, 35)); Welcome_Label.setBounds(240, 20, 600, 60); Latitude_Label = new JLabel("Latitude:"); Latitude_Label.setForeground(Color.BLACK); Latitude_Label.setFont(new Font("Courier New", Font.PLAIN, 25)); Latitude_Label.setBounds(15, 80, 200, 100); Longitude_Label = new JLabel("Longitude:"); Longitude_Label.setForeground(Color.BLACK); Longitude_Label.setFont(new Font("Courier New", Font.PLAIN, 25)); Longitude_Label.setBounds(15, 130, 250, 100); Radius_Label = new JLabel("Radius:"); Radius_Label.setForeground(Color.BLACK); Radius_Label.setFont(new Font("Courier New", Font.PLAIN, 25)); Radius_Label.setBounds(15, 180, 250, 100); Category_Label = new JLabel("Category:"); Category_Label.setForeground(Color.BLACK); Category_Label.setFont(new Font("Courier New", Font.PLAIN, 25)); Category_Label.setBounds(15, 250, 250, 100); Latitude_TextField = new JTextField(7); Latitude_TextField.setForeground(Color.BLACK); Latitude_TextField.setBounds(165, 116, 180, 30); Longitude_TextField = new JTextField(7); Longitude_TextField.setForeground(Color.BLACK); Longitude_TextField.setBounds(170, 168, 180, 30); Radius_TextField = new JTextField(7); Radius_TextField.setForeground(Color.BLACK); Radius_TextField.setBounds(125, 215, 180, 30); Categories = new JComboBox(Categories_Names); Categories.setForeground(Color.BLACK); Categories.setBackground(Color.white); Categories.setBounds(15, 320, 180, 30); POI_List = new ArrayList(); pane = getContentPane(); //Manager pane.setLayout(null); // Deactivate Manager Layout //JPANEL P = new JPanel(); P.setBackground(Color.GRAY); P.setBounds(600, 120, 450, 180); P.setBackground(Color.GRAY); pane.add(P); pane.add(POIS_Label); pane.add(Retrieve_POIs_Button); pane.add(Welcome_Label); pane.add(Longitude_Label); pane.add(Latitude_Label); pane.add(Radius_Label); pane.add(Category_Label); pane.add(Latitude_TextField); pane.add(Longitude_TextField); pane.add(Radius_TextField); pane.add(Categories); pane.add(Open_Status); Retrieve_POIs_Button.addActionListener(this); setContentPane(pane); }
From source file:io.github.jeremgamer.editor.panels.Actions.java
public Actions(final JFrame frame, final ActionPanel ap) { this.frame = frame; this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;//from ww w.j av a2 s . c o m try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog(null, "Nommez l'action :", "Crer une action", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new ActionSave(name); OtherPanel.updateLists(); ButtonPanel.updateLists(); ActionPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (actionList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/actions/" + actionList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog(null, "tes-vous sr de vouloir supprimer cette action?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { if (actionList.getSelectedValue().equals(ap.getFileName())) { ap.setFileName(""); } ap.hide(); file.delete(); data.remove(actionList.getSelectedIndex()); OtherPanel.updateLists(); ButtonPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); actionList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { ap.show(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { ap.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { ap.hideThenShow(); previousSelection = list.getSelectedValue(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { ap.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { ap.show(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { ap.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { ap.hideThenShow(); previousSelection = list.getSelectedValue(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { ap.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(actionList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); OtherPanel.updateLists(); }
From source file:modelibra.swing.app.util.FileSelector.java
/** * Prompts a user to decide if the file should be replaced: yes or no. * // w ww . j a va2s. c om * @param parentFrame * parent window * @param lang * language * @return <code>true</code> if a user chooses yes */ protected boolean replaceFile(JFrame parentFrame, NatLang lang) { // Custom button text Object[] options = { lang.getText("yes"), lang.getText("no") }; JOptionPane.setDefaultLocale(lang.getLocale()); int response = JOptionPane.showOptionDialog(parentFrame, // parent // frame lang.getText("replaceFile"), // message lang.getText("fileExists"), // title JOptionPane.YES_NO_OPTION, // option type JOptionPane.QUESTION_MESSAGE, // message type null, // don't use a custom icon options, // the titles of buttons options[0]); // default button title if (response == JOptionPane.NO_OPTION) { return false; } return true; }
From source file:com.mindcognition.mindraider.ui.swing.explorer.NotebooksTreeToolbar.java
public void actionPerformed(ActionEvent e) { // find notebook through node's user object URI, discard notebook (move it to the archive), // tags are preserved until notebook is erased DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) explorerJPanel.getNotebooksTree() .getLastSelectedPathComponent(); if (selectedNode.getDepth() == 0) { // it is leaf node - a notebook final String notebookUri = ((NotebookNodeUserObject) selectedNode.getUserObject()).getNotebookUri(); ResourceDescriptor resourceDescriptor = MindRaider.labelCustodian.getOutlineDescriptor(notebookUri); if (JOptionPane.showConfirmDialog(MindRaider.mainJFrame, "Do you really want to discard Outline '" + (resourceDescriptor != null ? resourceDescriptor.getLabel() : notebookUri) + "'?", "Archive Outline", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { // discard the notebook from ALL folders where it presents MindRaider.labelCustodian.discardOutline(notebookUri); explorerJPanel.refresh();/* w ww. j av a 2s . c om*/ OutlineJPanel.getInstance().clear(); MindRaider.spidersGraph.clear(); MindRaider.profile.setActiveOutlineUri(null); return; } } else { JOptionPane.showMessageDialog(MindRaider.mainJFrame, "Please select Outline to be discarded!"); } }
From source file:fi.elfcloud.client.tree.ClusterHierarchyModel.java
public void removeSelected(TreePath[] paths) { if (paths.length == 1) { ClusterTreeNode node = (ClusterTreeNode) paths[0].getLastPathComponent(); String dialogTitle = Messages.getString("ClusterHierarchyModel.title_vault_remove_dialog"); //$NON-NLS-1$ if (node instanceof DataItemNode) { dialogTitle = Messages.getString("ClusterHierarchyModel.title_dataitem_remove_dialog"); //$NON-NLS-1$ } else if (node.getParentId() > 0) { dialogTitle = Messages.getString("ClusterHierarchyModel.title_cluster_remove_dialog"); //$NON-NLS-1$ }//from w w w. j ava 2s .c o m int n = JOptionPane.showConfirmDialog(null, Messages.getString("ClusterHierarchyModel.dialog_remove_question") + node.getName() + "?", //$NON-NLS-1$ //$NON-NLS-2$ dialogTitle, JOptionPane.YES_NO_OPTION); switch (n) { case JOptionPane.YES_OPTION: removePaths(paths); break; default: break; } } else if (paths.length > 1) { int n = JOptionPane.showConfirmDialog(null, Messages.getString("ClusterHierarchyModel.dialog_remove_multiple_items_question"), //$NON-NLS-1$ Messages.getString("ClusterHierarchyModel.dialog_remove_multiple_items_title_1") //$NON-NLS-1$ + Integer.toString(paths.length) + Messages.getString("ClusterHierarchyModel.dialog_remove_multiple_items_title_2"), //$NON-NLS-1$ JOptionPane.YES_NO_OPTION); switch (n) { case JOptionPane.YES_OPTION: removePaths(paths); break; default: break; } } }
From source file:gda.gui.beans.SimpleBinaryBean.java
protected boolean executeCommand() { if (hasConfirmationDialog) { int dialogSelection = JOptionPane.showConfirmDialog(SimpleBinaryBean.this, dialogMessage, dialogTitle, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (dialogSelection == JOptionPane.NO_OPTION) return false; }/* w w w . jav a 2 s . c o m*/ return true; }
From source file:it.imtech.configuration.ChooseServer.java
/** * Connection serrver test, acquiring certificate if exists. * @param uri - Selected server URI/*w w w.j a v a 2s . c o m*/ * @return */ public static boolean testServerConnection(String uri) { Server s = (Server) choose_server.getSelectedItem(); boolean result = true; String outputFile = Globals.USER_DIR + "certs" + Utility.getSep() + "jssecacerts.jks"; //Aggiungo Keystore Temporaneo if (new File(outputFile).isFile()) { System.setProperty("javax.net.ssl.keyStore", outputFile); System.setProperty("javax.net.ssl.keyStorePassword", "changeit"); System.setProperty("javax.net.ssl.trustStore", outputFile); System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); } try { URL url = new URL("https://" + uri); URLConnection con = url.openConnection(); Reader reader = new InputStreamReader(con.getInputStream()); } catch (SSLHandshakeException ex) { ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); Object[] options = { Utility.getBundleString("voc1", bundle), Utility.getBundleString("voc2", bundle) }; int n = JOptionPane.showOptionDialog(null, Utility.getBundleString("phcertadd", bundle), Utility.getBundleString("phcertadd", bundle), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { String[] run = new String[1]; run[0] = uri + ":443"; AddToStoreKey.createAndShowGUI(run); result = false; } } catch (Exception ex) { } return result; }