Java Code Examples for javax.swing.JFrame#addWindowListener()
The following examples show how to use
javax.swing.JFrame#addWindowListener() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: beautyeye File: SwingSet2.java License: Apache License 2.0 | 6 votes |
/** * Create a frame for SwingSet2 to reside in if brought up * as an application. * * @param gc the gc * @return the j frame */ public static JFrame createFrame(GraphicsConfiguration gc) { JFrame frame = new JFrame(gc); if (numSSs == 0) { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } else { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { numSSs--; swingSets.remove(this); } }; frame.addWindowListener(l); } //由Jack Jiang于2012-09-22加上,防止因JToolBar的大小而影响JFrame的prefereSize使得没法再缩小 frame.setMinimumSize(new Dimension(100,100)); return frame; }
Example 2
Source Project: arcgis-runtime-demo-java File: AddAndMoveGraphicsApp.java License: Apache License 2.0 | 6 votes |
/** * Creates the application window. * * @return a window. */ private JFrame createWindow() { JFrame window = new JFrame("Add and Move Graphics Application"); window.setSize(1000, 1000); window.setLocationRelativeTo(null); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.getContentPane().setLayout(new BorderLayout(0, 0)); window.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent windowEvent) { super.windowClosing(windowEvent); if (map != null) { map.dispose(); } } }); return window; }
Example 3
Source Project: SPIM_Registration File: ViewSetupExplorer.java License: GNU General Public License v2.0 | 6 votes |
public ViewSetupExplorer( final AS data, final String xml, final X io ) { frame = new JFrame( "ViewSetup Explorer" ); panel = new ViewSetupExplorerPanel< AS, X >( this, data, xml, io ); frame.add( panel, BorderLayout.CENTER ); frame.setSize( panel.getPreferredSize() ); frame.addWindowListener( new WindowAdapter() { @Override public void windowClosing( WindowEvent evt ) { quit(); } }); frame.pack(); frame.setVisible( true ); // set the initial focus to the table panel.table.requestFocus(); }
Example 4
Source Project: jdk8u_jdk File: TableExample2.java License: GNU General Public License v2.0 | 6 votes |
public TableExample2(String URL, String driver, String user, String passwd, String query) { JFrame frame = new JFrame("Table"); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); JDBCAdapter dt = new JDBCAdapter(URL, driver, user, passwd); dt.executeQuery(query); // Create the table JTable tableView = new JTable(dt); JScrollPane scrollpane = new JScrollPane(tableView); scrollpane.setPreferredSize(new Dimension(700, 300)); frame.getContentPane().add(scrollpane); frame.pack(); frame.setVisible(true); }
Example 5
Source Project: jdk8u60 File: TableExample2.java License: GNU General Public License v2.0 | 6 votes |
public TableExample2(String URL, String driver, String user, String passwd, String query) { JFrame frame = new JFrame("Table"); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); JDBCAdapter dt = new JDBCAdapter(URL, driver, user, passwd); dt.executeQuery(query); // Create the table JTable tableView = new JTable(dt); JScrollPane scrollpane = new JScrollPane(tableView); scrollpane.setPreferredSize(new Dimension(700, 300)); frame.getContentPane().add(scrollpane); frame.pack(); frame.setVisible(true); }
Example 6
Source Project: mmscomputing File: TwainAppletExample.java License: GNU Lesser General Public License v3.0 | 6 votes |
public TwainAppletExample(String title, String[] argv){ JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame=new JFrame(title); // frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { stop();System.exit(0); } }); init(); frame.getContentPane().add(this); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); start(); }
Example 7
Source Project: biojava File: MultipleAlignmentJmolDisplay.java License: GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates a new Frame with the MultipleAlignment Sequence Panel. * The panel can communicate with the Jmol 3D visualization by * selecting the aligned residues of every structure. * * @param multAln * @param jmol * @throws StructureException */ public static void showMultipleAligmentPanel(MultipleAlignment multAln, AbstractAlignmentJmol jmol) throws StructureException { MultipleAligPanel me = new MultipleAligPanel(multAln, jmol); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setTitle(jmol.getTitle()); me.setPreferredSize(new Dimension( me.getCoordManager().getPreferredWidth() , me.getCoordManager().getPreferredHeight())); JMenuBar menu = MenuCreator.getAlignmentPanelMenu( frame,me,null, multAln); frame.setJMenuBar(menu); JScrollPane scroll = new JScrollPane(me); scroll.setAutoscrolls(true); MultipleStatusDisplay status = new MultipleStatusDisplay(me); me.addAlignmentPositionListener(status); Box vBox = Box.createVerticalBox(); vBox.add(scroll); vBox.add(status); frame.getContentPane().add(vBox); frame.pack(); frame.setVisible(true); frame.addWindowListener(me); frame.addWindowListener(status); }
Example 8
Source Project: openjdk-8-source File: MultiGradientTest.java License: GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { final JFrame frame = new JFrame("Multistop Gradient Demo"); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.dispose(); } }); frame.add(new MultiGradientTest()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
Example 9
Source Project: BigStitcher File: StitchingExplorerPanel.java License: GNU General Public License v2.0 | 5 votes |
private void initLinkExplorer() { // we already should have an instance if ( linkExplorer != null ) return; linkExplorer = new LinkExplorerPanel( stitchingResults, (StitchingExplorerPanel< AbstractSpimData< ? >, ? >) this ); // init the LinkExplorer linkFrame = new JFrame( "Link Explorer" ); linkFrame.add( linkExplorer, BorderLayout.CENTER ); linkFrame.setSize( linkExplorer.getPreferredSize() ); linkFrame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent evt) { setSavedFilteringAndGrouping( null ); togglePreviewMode(false); } } ); linkFrame.pack(); linkFrame.setVisible( true ); linkFrame.requestFocus(); MultiWindowLayoutHelper.moveToScreenFraction( linkFrame, xPosLinkExplorer, yPosLinkExplorer ); }
Example 10
Source Project: doov File: BenchmarkUI.java License: Apache License 2.0 | 5 votes |
public static void main(String[] args) { final TimeSeriesCollection dataSet = new TimeSeriesCollection(); final TimeSeries series_doov = new TimeSeries("dOOv"); final TimeSeries series_bareMetal = new TimeSeries("Bare Metal"); final TimeSeries series_beanValidation = new TimeSeries("Bean Validation - HV 6.0.7"); dataSet.addSeries(series_doov); dataSet.addSeries(series_bareMetal); dataSet.addSeries(series_beanValidation); final JFrame f = new JFrame(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setSize(new Dimension(1280, 1024)); f.getContentPane().add(new ChartPanel(createTimeSeriesChart("dOOv benchmark", "time", "hits", dataSet)), BorderLayout.CENTER); f.setVisible(true); final BareMetalRunnable bareRunnable = new BareMetalRunnable(); final DoovRunnable doovRunnable = new DoovRunnable(); final BeanValidationRunnable beanValidationRunnable = new BeanValidationRunnable(); new Thread(beanValidationRunnable).start(); new Thread(bareRunnable).start(); new Thread(doovRunnable).start(); new Timer().schedule(new TimerTask() { @Override public void run() { SwingUtilities.invokeLater(() -> { final Second second = new Second(); series_doov.addOrUpdate(second, doovRunnable.hits.get()); series_bareMetal.addOrUpdate(second, bareRunnable.hits.get()); series_beanValidation.addOrUpdate(second, beanValidationRunnable.hits.get()); }); } }, 0, 200); }
Example 11
Source Project: birt File: Regression_119808.java License: Eclipse Public License 1.0 | 5 votes |
/** * Contructs the layout with a container for displaying chart and a control * panel for selecting interactivity. * * @param args */ public static void main( String[] args ) { final Regression_119808 siv = new Regression_119808( ); JFrame jf = new JFrame( ); jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); jf.addComponentListener( siv ); Container co = jf.getContentPane( ); co.setLayout( new BorderLayout( ) ); co.add( siv, BorderLayout.CENTER ); Dimension dScreen = Toolkit.getDefaultToolkit( ).getScreenSize( ); Dimension dApp = new Dimension( 600, 400 ); jf.setSize( dApp ); jf.setLocation( ( dScreen.width - dApp.width ) / 2, ( dScreen.height - dApp.height ) / 2 ); jf.setTitle( siv.getClass( ).getName( ) + " [device=" //$NON-NLS-1$ + siv.idr.getClass( ).getName( ) + "]" );//$NON-NLS-1$ ControlPanel cp = siv.new ControlPanel( siv ); co.add( cp, BorderLayout.SOUTH ); siv.idr.setProperty( IDeviceRenderer.UPDATE_NOTIFIER, siv ); jf.addWindowListener( new WindowAdapter( ) { public void windowClosing( WindowEvent e ) { siv.idr.dispose( ); } } ); jf.setVisible( true ); }
Example 12
Source Project: arcgis-runtime-demo-java File: GeometryApp.java License: Apache License 2.0 | 5 votes |
/** * Creates a window. * @return a window. */ private JFrame createWindow() { JFrame window = new JFrame(); window.setBounds(100, 100, 1000, 700); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.getContentPane().setLayout(new BorderLayout(0, 0)); window.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent windowEvent) { super.windowClosing(windowEvent); map.dispose(); } }); return window; }
Example 13
Source Project: megamek File: MegaMekGUI.java License: GNU General Public License v2.0 | 5 votes |
/** * Hides this window for later. Listens to the frame until it closes, then * calls unlaunch(). */ private void launch(JFrame launched) { // listen to new frame launched.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { unlaunch(); } }); // hide menu frame frame.setVisible(false); }
Example 14
Source Project: netbeans File: RendererDisplayerTest.java License: Apache License 2.0 | 5 votes |
public WaitWindow(JFrame f) { f.addWindowListener(this); f.show(); if (!shown) { synchronized(this) { try { //System.err.println("Waiting for window"); wait(5000); } catch (Exception e) {} } } }
Example 15
Source Project: jmonkeyengine File: TestSafeCanvas.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) throws InterruptedException{ AppSettings settings = new AppSettings(true); settings.setWidth(640); settings.setHeight(480); final TestSafeCanvas app = new TestSafeCanvas(); app.setPauseOnLostFocus(false); app.setSettings(settings); app.createCanvas(); app.startCanvas(true); JmeCanvasContext context = (JmeCanvasContext) app.getContext(); Canvas canvas = context.getCanvas(); canvas.setSize(settings.getWidth(), settings.getHeight()); Thread.sleep(3000); JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { app.stop(); } }); frame.getContentPane().add(canvas); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); Thread.sleep(3000); frame.getContentPane().remove(canvas); Thread.sleep(3000); frame.getContentPane().add(canvas); }
Example 16
Source Project: openjdk-jdk9 File: WindowClosedEventOnDispose.java License: GNU General Public License v2.0 | 5 votes |
/** * Test if a Window that has never been shown fire the * WINDOW_CLOSED event on dispose() */ public static void testHidenWindowDispose() throws Exception { JFrame f = new JFrame(); Listener l = new Listener(); f.addWindowListener(l); f.dispose(); waitEvents(); assertEquals(0, l.getCount()); }
Example 17
Source Project: Any-Angle-Pathfinding File: Visualisation.java License: The Unlicense | 5 votes |
/** * Spawns the visualisation window for the algorithm. */ protected static void setupMainFrame(DrawCanvas drawCanvas, ArrayList<GridObjects> gridObjectsList) { KeyToggler keyToggler = new KeyToggler(drawCanvas, gridObjectsList); JFrame mainFrame = new JFrame(); mainFrame.add(drawCanvas); mainFrame.addKeyListener(keyToggler); mainFrame.addWindowListener(new CloseOnExitWindowListener()); mainFrame.setResizable(false); mainFrame.pack(); mainFrame.setLocationRelativeTo(null); mainFrame.setVisible(true); }
Example 18
Source Project: arcgis-runtime-demo-java File: GeometryOfflineApp.java License: Apache License 2.0 | 5 votes |
/** * Creates a window. * @return a window. */ private JFrame createWindow() { JFrame window = new JFrame(); window.setExtendedState(Frame.MAXIMIZED_BOTH); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.getContentPane().setLayout(new BorderLayout(0, 0)); window.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent windowEvent) { super.windowClosing(windowEvent); map.dispose(); } }); return window; }
Example 19
Source Project: jcuda-samples File: JCudaDriverSimpleLWJGL.java License: MIT License | 5 votes |
/** * Creates a new JCudaDriverSimpleLWJGL. */ public JCudaDriverSimpleLWJGL() { simpleInteraction = new SimpleInteraction(); // Initialize the GL component createCanvas(); // Initialize the mouse and keyboard controls MouseControl mouseControl = simpleInteraction.getMouseControl(); glComponent.addMouseMotionListener(mouseControl); glComponent.addMouseWheelListener(mouseControl); KeyboardControl keyboardControl = new KeyboardControl(); glComponent.addKeyListener(keyboardControl); // Create the main frame frame = new JFrame("JCuda / LWJGL interaction sample"); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setLayout(new BorderLayout()); glComponent.setPreferredSize(new Dimension(800, 800)); frame.add(glComponent, BorderLayout.CENTER); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); glComponent.requestFocus(); }
Example 20
Source Project: openjdk-jdk8u-backup File: CompositionArea.java License: GNU General Public License v2.0 | 5 votes |
CompositionArea() { // create composition window with localized title String windowTitle = Toolkit.getProperty("AWT.CompositionWindowTitle", "Input Window"); compositionWindow = (JFrame)InputMethodContext.createInputMethodWindow(windowTitle, null, true); setOpaque(true); setBorder(LineBorder.createGrayLineBorder()); setForeground(Color.black); setBackground(Color.white); // if we get the focus, we still want to let the client's // input context handle the event enableInputMethods(true); enableEvents(AWTEvent.KEY_EVENT_MASK); compositionWindow.getContentPane().add(this); compositionWindow.addWindowListener(new FrameWindowAdapter()); addInputMethodListener(this); compositionWindow.enableInputMethods(false); compositionWindow.pack(); Dimension windowSize = compositionWindow.getSize(); Dimension screenSize = (getToolkit()).getScreenSize(); compositionWindow.setLocation(screenSize.width - windowSize.width-20, screenSize.height - windowSize.height-100); compositionWindow.setVisible(false); }