List of usage examples for javax.swing JInternalFrame IS_CLOSED_PROPERTY
String IS_CLOSED_PROPERTY
To view the source code for javax.swing JInternalFrame IS_CLOSED_PROPERTY.
Click Source Link
From source file:OptPaneComparison.java
public OptPaneComparison(final String message) { setDefaultCloseOperation(EXIT_ON_CLOSE); final int msgType = JOptionPane.QUESTION_MESSAGE; final int optType = JOptionPane.OK_CANCEL_OPTION; final String title = message; setSize(350, 200);/*from w w w.j a va2 s . c o m*/ // Create a desktop for internal frames final JDesktopPane desk = new JDesktopPane(); setContentPane(desk); // Add a simple menu bar JMenuBar mb = new JMenuBar(); setJMenuBar(mb); JMenu menu = new JMenu("Dialog"); JMenu imenu = new JMenu("Internal"); mb.add(menu); mb.add(imenu); final JMenuItem construct = new JMenuItem("Constructor"); final JMenuItem stat = new JMenuItem("Static Method"); final JMenuItem iconstruct = new JMenuItem("Constructor"); final JMenuItem istat = new JMenuItem("Static Method"); menu.add(construct); menu.add(stat); imenu.add(iconstruct); imenu.add(istat); // Create our JOptionPane. We're asking for input, so we call // setWantsInput. // Note that we cannot specify this via constructor parameters. optPane = new JOptionPane(message, msgType, optType); optPane.setWantsInput(true); // Add a listener for each menu item that will display the appropriate // dialog/internal frame construct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JDialog d = optPane.createDialog(desk, title); d.setVisible(true); respond(getOptionPaneValue()); } }); stat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInputDialog(desk, message, title, msgType); respond(s); } }); iconstruct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JInternalFrame f = optPane.createInternalFrame(desk, title); f.setVisible(true); // Listen for the frame to close before getting the value from // it. f.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent ev) { if ((ev.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) && (ev.getNewValue() == Boolean.TRUE)) { respond(getOptionPaneValue()); } } }); } }); istat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInternalInputDialog(desk, message, title, msgType); respond(s); } }); }
From source file:org.nuclos.client.ui.collect.CollectController.java
protected void initTab() { // prevent that the frame is closed when changes are pending: getTab().addVetoableChangeListener(new VetoableChangeListener() { @Override/*from ww w . j a v a 2 s. c o m*/ public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { if (evt.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) { final Boolean bOldValue = (Boolean) evt.getOldValue(); final Boolean bNewValue = (Boolean) evt.getNewValue(); if (bOldValue == Boolean.FALSE && bNewValue == Boolean.TRUE) { // We need bFrameMayBeClosed as a member variable here, as it is set in // cmdFrameClosing and must be checked here. // JInternalFrame.setClosed() first sends a frame closing event, then a vetoable change event. // Note that this is totally weird. See JInternalFrame.setClosed() if (!CollectController.this.bFrameMayBeClosed) { throw new PropertyVetoException("do not close", evt); } } } } }); // override close behavior: getTab().addMainFrameTabListener(new MainFrameTabAdapter() { @Override public void tabSelected(MainFrameTab tab) { setDefaultButton(); } @Override public void tabClosing(MainFrameTab tab, final ResultListener<Boolean> rl) { askAndSaveIfNecessary(new ResultListener<Boolean>() { @Override public void done(Boolean result) { rl.done(Boolean.TRUE.equals(result)); } }); } @Override public void tabClosed(MainFrameTab tab) { CollectController.this.close(); tab.removeMainFrameTabListener(this); } }); }