public void run() { String command = inputTextArea.getText().trim(); if (command == null || command.length() == 0) { JOptionPane.showMessageDialog( mainWindow, "Command window is empty", "Out of order", JOptionPane.WARNING_MESSAGE); return; } // make busy dialog same width as main window. Dimension dlgBounds = busyDialog.getSize(); dlgBounds.width = mainWindow.getSize().width; busyDialog.setSize(dlgBounds); runButton.setEnabled(false); Configuration config = (Configuration) connectionsList.getSelectedItem(); if (passwdPromptCheckBox.isSelected() || !config.hasPassword()) { String pass = getPassword("Connection password for " + config.getName()); config.setPassword(pass); } resultsStatusBar.reset(); busyDialog.setVisible(true); try { currentConnection = configManager.getConnection(config); SQLRunner.setVerbosity(Verbosity.QUIET); SQLRunner prog = new SQLRunner(currentConnection, null, "t"); prog.setGUI(SQLRunnerGUI.this); if (mode != null) { prog.setOutputMode(mode); } prog.setOutputFile(out); // RUN THE SQL prog.runStatement(command); if (prog.isEscape()) { outputPanel.setSelectedIndex(0); } resultsStatusBar.showSuccess(); // If no exception thrown! } catch (Exception e) { resultsStatusBar.showFailure(); eHandler.handleError(e); } finally { runButton.setEnabled(true); busyDialog.setVisible(false); try { // Nested try here is deliberate, not a big deal if this call crashes if (currentConnection != null) { currentConnection.close(); } } catch (SQLException ex) { System.err.println("Warning: close caused " + ex); } } }
public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == jbNewPlayer) { if (currentPlayer == null) { JFrame playerBuild = new JFrame(); playerBuild.setContentPane(new NewPlayer(this, playerBuild, dataBank)); playerBuild.pack(); playerBuild.setVisible(true); } else parent.startMordor(currentPlayer); } else if (e.getSource() == jbLoadPlayer) { if (currentPlayer != null) updatePlayer(null); else { if (dataBank.getPlayers().getSize() > 0) { String playerName = (String) JOptionPane.showInputDialog( this, "Choose player", "Player", JOptionPane.PLAIN_MESSAGE, null, dataBank.getPlayerNames(), 0); updatePlayer(dataBank.getPlayer(playerName)); } else JOptionPane.showMessageDialog(this, "No players to load."); } } else if (e.getSource() == jbExchangeItems) { JDialog exchangeDialog = new JDialog(this.parent, "Item Exchange", true); exchangeDialog.setContentPane(new ExchangeItems(exchangeDialog, dataBank)); exchangeDialog.pack(); exchangeDialog.setVisible(true); } else if (e.getSource() == jbChangePassword) { } else if (e.getSource() == jbDeletePlayer) { dataBank.removePlayer(currentPlayer); updatePlayer(null); } else if (e.getSource() == jbPlayerList) { JDialog playerDialog = new JDialog(this.parent, "Player List", true); playerDialog.setContentPane(new PlayerList(dataBank.getPlayers())); playerDialog.pack(); playerDialog.setVisible(true); } else if (e.getSource() == jbHallOfRecords) { JDialog horDialog = new JDialog(this.parent, "Hall of Records", true); horDialog.setContentPane(new HallOfRecords(horDialog, dataBank.getPlayers())); horDialog.pack(); horDialog.setVisible(true); } else if (e.getSource() == jbHelpLesson) { } else if (e.getSource() == jbOptions) { } else if (e.getSource() == jbExit) { parent.quitMordor(); } else if (e.getSource() == jbAbout) { JOptionPane.showMessageDialog(this, parent.aboutMordor); } }
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == okButton) { if (original != null) { original.restoreState(config); } dialog.setVisible(false); } else if (e.getSource() == cancelButton) { dialog.setVisible(false); } }
@Override public void setVisible(boolean isVisible) { if (isVisible == false) { super.setVisible(isVisible); return; } // Reset all the components clear(); super.setVisible(isVisible); }
/** * Pops up a "Tip of the day" dialog. * * <p>If <code>choice</code> is not null, the method first checks if <code>force</code> is true or * if {@link ShowOnStartupChoice#isShowingOnStartup()} is true before showing the dialog. * * <p>Additionally, it saves the state of the "Show tips on startup" checkbox using the given * {@link ShowOnStartupChoice} object. * * @param parentComponent * @param choice * @param force if true, the dialog is displayed even if {@link * ShowOnStartupChoice#isShowingOnStartup()} is false * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true. * @see java.awt.GraphicsEnvironment#isHeadless * @return true if the user chooses to see the tips again, false otherwise. */ public boolean showDialog(Component parentComponent, ShowOnStartupChoice choice, boolean force) { if (choice == null) { JDialog dialog = createDialog(parentComponent, choice); dialog.setVisible(true); dialog.dispose(); return true; } else if (force || choice.isShowingOnStartup()) { JDialog dialog = createDialog(parentComponent, choice); dialog.setVisible(true); dialog.dispose(); return choice.isShowingOnStartup(); } else { return false; } }
/** * @param editor * @param idDialog * @param dialog * @param title */ public static void setDialogVisible( @Nullable Editor editor, String idDialog, JDialog dialog, String title) { Point location = null; if (editor != null) { Point caretLocation = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition()); SwingUtilities.convertPointToScreen(caretLocation, editor.getComponent()); String[] position = UtilsPreferences.getDialogPosition(idDialog).split("x"); if (!(position[0].equals("0") && position[1].equals("0"))) { location = new Point(Integer.parseInt(position[0]), Integer.parseInt(position[1])); } } if (location == null) { // Center to screen dialog.setLocationRelativeTo(null); } else { dialog.setLocation(location.x, location.y); } dialog.setTitle(title); dialog.pack(); dialog.setVisible(true); }
public static void aboutSystem(Frame owner) { JDialog dialog = new JDialog(owner, "System Properties"); // $NON-NLS-1$ DiagnosticsForSystem viewer = new DiagnosticsForSystem(); dialog.setContentPane(viewer); dialog.setSize(500, 300); dialog.setVisible(true); }
@Override public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); if(keyCode == KeyEvent.VK_ENTER){ final JDialog dialog = new JDialog(); dialog.setTitle("Search results"); dialog.setModal(true); int height = 40; dialog.setBounds(0, 0, 300, 500); JPanel panel = new JPanel(); ArrayList list = DataLayer.search(zoekBalk.getText()); panel.setLayout(new GridLayout(list.size(), 1)); if(list.size() == 0){ JOptionPane.showMessageDialog(null, zoekBalk.getText() + " kon niet gevonden worden/ bestaat niet!", "Niet gevonden", JOptionPane.INFORMATION_MESSAGE); //panel.add(new JLabel(zoekBalk.getText() + " kon niet gevonden worden/ bestaat niet!")); }else{ for(int i = 0; i < list.size(); i++){ panel.add(new JLabel(list.get(i).toString())); height = height + 20; } dialog.setPreferredSize(new Dimension(200, height)); dialog.add(panel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.validate(); } } }
@Test public void test2dPlot() { double[] x = new double[100]; // 1000 random numbers from a normal (Gaussian) statistical law double[] y = new double[100]; for (int i = 0; i < x.length; i++) { x[i] = i * 0.5; y[i] = Math.sin(x[i]); } Plot2DPanel plot = new Plot2DPanel(); // add a line plot to the PlotPanel plot.addLinePlot("my plot", x, y); plot.setFixedBounds(0, 0, 10); plot.setFixedBounds(1, -10, 10); plot.getAxis(0).setLightLabels(); JFrame frame = new JFrame("a plot panel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JDialog dlg = new JDialog(frame, true); dlg.setContentPane(plot); dlg.pack(); dlg.setVisible(true); }
private void displayFilteredDialog() { try { log.debug("displayFilteredDialog: subAction name = " + this.m_subAction.sub_action_name()); // toolbarAction parentAction = getParentAction(); JDialog initDebaterecord; initDebaterecord = new JDialog(); initDebaterecord.setTitle("Enter Settings for Document"); initDebaterecord.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // initDebaterecord.setPreferredSize(new Dimension(420, 300)); InitDebateRecord panel = new InitDebateRecord(ooDocument, initDebaterecord, m_parentAction, m_subAction); // panel.setDialogMode(SelectorDialogModes.TEXT_INSERTION); // panel.setBackground(new Color(255, 255, 153)); // initDebaterecord.setTitle("Selection Mode"); initDebaterecord.getContentPane().add(panel); initDebaterecord.pack(); initDebaterecord.setLocationRelativeTo(null); initDebaterecord.setVisible(true); initDebaterecord.setAlwaysOnTop(true); } catch (Exception ex) { log.error("displayFilteredDialog : " + ex.getMessage()); log.error( "displayFilteredDialog: stack trace : \n" + org.bungeni.ooo.utils.CommonExceptionUtils.getStackTrace(ex)); } }
/** * Displays a dialog with a scrollable, double-click enabled JTable. Returns the Row/Column * clicked or null if Canceled/Exited * * @param table The prepared JTable to be encapsulated in a JScollPane and a mouse event listener * added * @param message the message to be displayed * @return Row and Column (index 0 and 1 respectively) or null if no input */ public static int[] jTableDialog(JTable table, String message) { JScrollPane scroller = new JScrollPane(table); // add scroll pane to table Object[] mssg = {message, scroller}; Object[] options = {"OK", "Cancel"}; JOptionPane pane = new JOptionPane( mssg, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, scroller); final JDialog dialog = pane.createDialog("Please make a selection"); table.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2) { dialog.dispose(); } } }); dialog.setResizable(true); dialog.setVisible(true); if (table.getSelectedRow() == -1 || table.getSelectedColumn() == -1 || options[1].equals(pane.getValue())) return null; int[] ret = {table.getSelectedRow(), table.getSelectedColumn()}; return ret; }
public static boolean openPortSettingsDialog( SerialPortConnection port, String title, String message) { port.closeConnection(); JOptionPane optionPane = new JOptionPane(); PanelSerialConfig configPanel = new PanelSerialConfig(port); Object msg[] = {message, configPanel}; optionPane.setMessage(msg); optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE); optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION); JDialog dialog = optionPane.createDialog(null, title); dialog.setVisible(true); Object value = optionPane.getValue(); if (value == null || !(value instanceof Integer)) { System.out.println("Closed"); } else { int i = ((Integer) value).intValue(); if (i == JOptionPane.OK_OPTION) { try { port.getParameters().save(); // setCommPort(getPort().getParameters().getPortName()); } catch (Exception ex) { ex.printStackTrace(); } // re-open the port port.reOpenConnection(); // System.out.println("OKAY - value is: " + optionPane.getInputValue()); } else { return false; } } return true; }
@Override public void onCannotStonePlaced() { JDialog diag = new JDialog(this, CANNOT_PLACE, true); diag.setSize(new Dimension(300, 200)); JPanel pan = new JPanel(new BorderLayout()); JLabel lab = new JLabel(CANNOT_PLACE_MSG); lab.setSize(280, 190); pan.add(lab, BorderLayout.CENTER); JButton but = new JButton(VERIFY); pan.add(but, BorderLayout.SOUTH); final JDialog dia = diag; but.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dia.dispose(); } }); diag.getContentPane().add(pan); diag.setLocationRelativeTo(null); diag.setVisible(true); }
/** * Shows the dialog. First a dialog must be constructed using one of the constructors of this * class. After that this method should be called to actually show the dialog. This method returns * either JOptionPane.OK_OPTION if the user wants to select his choices or * JOptionPane.CANCEL_OPTION if he does not want to. * * @param parent The parent frame of this dialog. * @return int The returnvalue, can be either JOptionPane.OK_OPTION or JOptionPane.CANCEL_OPTION */ public int showDialog(Component parent) { Frame frame = parent instanceof Frame ? (Frame) parent : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); // String title = getUI().getDialogTitle(this); dialog = new JDialog(frame, title, true); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(this, BorderLayout.CENTER); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { cancel(); } }); dialog.pack(); dialog.setLocationRelativeTo(parent); dialog.setVisible(true); return returnValue; }
@Override public void setVisible(boolean b) { if (b) { SwingUtil.centerOver(this, getOwner()); } super.setVisible(b); }
/** * This constructor creates a new message window with the information of an email on which the * user wants to respond * * @param message : stores information of an email on which we want to respond * @throws MessagingException : Throws exception to the the function where an object of type * SendMessage has been instantiate * @throws IOException : Throws exception to the the function where an object of type SendMessage * has been instantiate */ public SendMessage(Message message) throws MessagingException, IOException { this.message = message; textArea = new JTextArea(); scrollPane = new JScrollPane(textArea); wrongMailsStringBuilder = new StringBuilder(); window = new JDialog(); username = "******"; userPassword = "******"; width = 800; height = 500; messageHandler = new MessageHandler(message); window.setSize(width, height); window.setName("send a new E-Mail"); window.setVisible(true); setTextArea(); createToLabel(); createCcLabel(); createBccLabel(); createSubjectLabel(); createCcField(); createBccField(); createSendButton(); createCancelButton(); createSaveButton(); createFormular(messageHandler, message); createContainer(); setWindowConfiguration(); }
@Override public void setVisible(boolean visible) { if (visible) { WindowGeometry.centerInWindow(Main.parent, new Dimension(350, 300)).applySafe(this); } super.setVisible(visible); }
private int getConfirmChoice(String match) { Object[] btns = getConfirmButtons(); confirmDlg = new JOptionPane( "Replace with " + match + " ?", JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, btns, btns[0]); JDialog dlg = confirmDlg.createDialog(null, "Confirm Replace"); dlg.setVisible(true); Object res = confirmDlg.getValue(); confirmDlg = null; if (res == null) { return JOptionPane.CLOSED_OPTION; } for (int i = 0; i < btns.length; i++) { if (btns[i].equals(res)) { return i; } } return JOptionPane.CLOSED_OPTION; }
/** Show the dialog. if c is null, the dialog will not have a parent. */ public int showDialog(Component c) { Window topLevel = null; if (c != null) { topLevel = SwingUtilities.getWindowAncestor(c); } if (topLevel == null) { dialog = new JDialog(); dialog.setModal(true); } else if (topLevel instanceof Frame) { dialog = new JDialog((Frame) topLevel, true); } else if (topLevel instanceof Dialog) { dialog = new JDialog((Dialog) topLevel, true); } dialog.getContentPane().add(this); dialog.setDefaultCloseOperation(dialog.DISPOSE_ON_CLOSE); dialog.setTitle("Arithmetic operation"); dialog.pack(); Misc.centerFrame(dialog); dialog.setVisible(true); return getDialogResult(); }
@Override public void actionPerformed(ActionEvent actionEvent) { Dimension all = parent.getSize(); Dimension d = dialog.getSize(); dialog.setLocation((all.width - d.width) / 2, (all.height - d.height) / 2); dialog.setVisible(true); }
public void login() { if (DataUser.getUsr() == null) { LoginDialog form = new LoginDialog(); ODatabaseDocumentTx db = App.getDbd(); ODatabaseRecordThreadLocal.INSTANCE.set(db); form.buildComponent(db); db.close(); JDialog d = new JDialog(frame); d.setModalityType(ModalityType.APPLICATION_MODAL); d.getContentPane().add(form.getPanel()); d.pack(); setCenterDialog(d); d.setVisible(true); } else { // logout DataUser.setUsr(null); DataUser.setGrp(null); closeAllWindow(); } DataUser.setAkses(); for (HakAksesListener hakAksesListener : cangeHakAkses) { hakAksesListener.changeHakAkses(); } // if (DataUser.usr != null) { // // open default like welcome // // } }
@Override public void setVisible(boolean b) { if (b) { saveAndSetPropertyValues(); } super.setVisible(b); }
static void tell(String question, String btnText) { final JDialog d = new JDialog(); d.setLocationRelativeTo(null); JPanel bpane = new JPanel(new FlowLayout()); JLabel l = new JLabel(question); JPanel cp = (JPanel) d.getContentPane(); cp.setLayout(new FlowLayout()); cp.add(l, BorderLayout.CENTER); cp.add(bpane, BorderLayout.SOUTH); JButton b1 = new JButton("OK"); bpane.add(b1); d.pack(); d.setVisible(true); b1.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ans = ((JButton) e.getSource()).getText(); d.dispose(); } }); }
public static char[] showPasswordDialog(Component parent, String titre) { final JPasswordField jpf = new JPasswordField(); JOptionPane jop = new JOptionPane(jpf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); // FIXME: label JDialog dialog = jop.createDialog(parent, titre); dialog.addComponentListener( new ComponentAdapter() { public void componentShown(ComponentEvent e) { jpf.requestFocusInWindow(); } }); dialog.setVisible(true); if (jop.getValue() == null) { return null; } int result = (Integer) jop.getValue(); dialog.dispose(); char[] password = null; if (result == JOptionPane.OK_OPTION) { password = jpf.getPassword(); } else { return null; } return password; }
public void run(DataLayer pnmlData) { // Build interface JDialog guiDialog = new JDialog(CreateGui.getApp(), MODULE_NAME, true); // 1 Set layout Container contentPane = guiDialog.getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); // 2 Add file browser contentPane.add(sourceFilePanel = new PetriNetChooserPanel("Source net", pnmlData)); // 3 Add results pane contentPane.add(results = new ResultsHTMLPane(pnmlData.getURI())); // 4 Add button contentPane.add(new ButtonBar("Analyse", analyseButtonClick)); // 5 Make window fit contents' preferred size guiDialog.pack(); // 6 Move window to the middle of the screen guiDialog.setLocationRelativeTo(null); guiDialog.setVisible(true); // warnUser(pnmlData.getURI(), guiFrame); // StateSpace stateSpace = new StateSpace(pnmlData); }
private void cancelButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_cancelButtonActionPerformed // TODO add your handling code here: cancel = true; dialog.setVisible(false); dialog.dispose(); } // GEN-LAST:event_cancelButtonActionPerformed
/** Show details. */ private void showDetails() { if (details == null) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { details = new JDialog( (JFrame) SwingUtilities.getRoot(QuaternaryVennExample.this), "Details"); QuaternaryVennList<String> list = new QuaternaryVennList<String>( vennNode.getFirstLabelText(), vennNode.getSecondLabelText(), vennNode.getThirdLabelText(), vennNode.getFourthLabelText(), vennNode.getModel()); list.setBorder(new EmptyBorder(20, 20, 20, 20)); details.setContentPane(list); details.setBounds(200, 200, 800, 800); details.setVisible(true); } }); } else { details.setVisible(true); details.requestFocusInWindow(); } }
public char[] askPassword() { char[] password = null; final JDialog dlg = new JDialog(frm, "Password", true); final JPasswordField jpf = new JPasswordField(15); final JButton[] btns = {new JButton("Enter"), new JButton("Cancel")}; for (int i = 0; i < btns.length; i++) { btns[i].addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dlg.setVisible(false); } }); } Object[] prts = new Object[] {"Please input a password:"******"Invalid password, passwords must be " + PASSWORD_MIN + " characters long"); System.exit(1); } return password; }
@Override public void actionPerformed(ActionEvent actionEvent) { String serverName = panel.getServerNameField().getText(); String serverAddress = panel.getServerAddressField().getText(); if (serverName == null || "".equals(serverName)) { JOptionPane.showMessageDialog(panel, "服务器名称不能为空", "错误", JOptionPane.ERROR_MESSAGE); return; } if (serverAddress == null || "".equals(serverAddress)) { JOptionPane.showMessageDialog(panel, "服务器地址不能为空", "错误", JOptionPane.ERROR_MESSAGE); return; } Server server = new Server(); server.setName(serverName); server.setAddress(serverAddress); server.setLatency(Server.NO_LATENCY); server.setStatus(Server.UNKNOWN); try { app.getServerRepository().saveServer(server); dialog.setVisible(false); } catch (DuplicateServerDefinitionException e) { JOptionPane.showMessageDialog(panel, e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE); } }
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == btn6) { la.setText("로그인 정보가 없습니다."); JOptionPane.showMessageDialog(this, "로그아웃되셨습니다."); new LoginGUI(this); } else if (e.getSource() == btn4) { System.out.println("버튼4"); TimeSeriesDemo demo = new TimeSeriesDemo("aa"); // ChartPanel cp = demo.TimeSerie(); // jp.getLeftComponent() // p4.add(cp); JDialog tsd_jd = new JDialog(this); // .add(demo.chartPanel); } else if (e.getSource() == btn5) { // p5.add(new BMIdemo()); } else if (e.getSource() == btn8) { JDialog jd = new JDialog(this); pie1 = pcd.createDemoPanel(); jd.add(pie1); jd.setVisible(true); jd.setSize(400, 400); jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } }