Java Code Examples for javax.swing.JFrame#setDefaultCloseOperation()

The following examples show how to use javax.swing.JFrame#setDefaultCloseOperation() . 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 File: Test8015926.java    From jdk8u_jdk with GNU General Public License v2.0 10 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 2
Source File: CDTaskManagerPanel.java    From moa with GNU General Public License v3.0 6 votes vote down vote up
private static void createAndShowGUI() {

        // Create and set up the window.
        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Create and set up the content pane.
        JPanel panel = new CDTaskManagerPanel();
        panel.setOpaque(true); // content panes must be opaque
        frame.setContentPane(panel);

        // Display the window.
        frame.pack();
        // frame.setSize(400, 400);
        frame.setVisible(true);
    }
 
Example 3
Source File: bug8136998.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void setupUI() {
    frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    comboBox = new JComboBox<>(ITEMS);

    JPanel scrollable = new JPanel();
    scrollable.setLayout(new BoxLayout(scrollable, BoxLayout.Y_AXIS));

    scrollable.add(Box.createVerticalStrut(200));
    scrollable.add(comboBox);
    scrollable.add(Box.createVerticalStrut(200));

    scrollPane = new JScrollPane(scrollable);

    frame.add(scrollPane);

    frame.setSize(100, 200);
    frame.setVisible(true);
}
 
Example 4
Source File: MultiLabelTaskManagerPanel.java    From moa with GNU General Public License v3.0 6 votes vote down vote up
private static void createAndShowGUI() {

        // Create and set up the window.
        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Create and set up the content pane.
        JPanel panel = new MultiLabelTaskManagerPanel();
        panel.setOpaque(true); // content panes must be opaque
        frame.setContentPane(panel);

        // Display the window.
        frame.pack();
        // frame.setSize(400, 400);
        frame.setVisible(true);
    }
 
Example 5
Source File: RetroWeaverGui.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private static void showInJFrame(String title, Component contents) {
	JFrame frame = new JFrame(title);
	frame.getContentPane().add(contents);
	frame.setSize(400, 300);
	centerOnScreen(frame);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setVisible(true);
}
 
Example 6
Source File: bug7170310.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowUI() {
    frame = new JFrame("bug7170310");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 100);

    tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Main Tab", new JPanel());

    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

    frame.getContentPane().add(tabbedPane);
    frame.setVisible(true);
}
 
Example 7
Source File: LinearGradientPrintingTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void createUI() {
    f = new JFrame("LinearGradient Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final LinearGradientPrintingTest gpt = new LinearGradientPrintingTest();
    Container c = f.getContentPane();
    c.add(BorderLayout.CENTER, gpt);

    final JButton print = new JButton("Print");
    print.addActionListener(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PrinterJob job = PrinterJob.getPrinterJob();
            job.setPrintable(gpt);
            final boolean doPrint = job.printDialog();
            if (doPrint) {
                try {
                    job.print();
                } catch (PrinterException ex) {
                    throw new RuntimeException(ex);
                }
            }
        }
    });
    c.add(print, BorderLayout.SOUTH);

    f.pack();
    f.setVisible(true);
}
 
Example 8
Source File: BasicDnD.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    frame = new JFrame("BasicDnD");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the content pane.
    JComponent newContentPane = new BasicDnD();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}
 
Example 9
Source File: JTableAccessibleGetLocationOnScreen.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void constructInEDT() {
    String[] columnNames = { "col1", "col2", };
    Object[][] data = { { "row1, col1", "row1, col2" },
            { "row2, col1", "row2, col2" }, };

    frame = new JFrame(
            "JTable AccessibleTableHeader and AccessibleJTableCell test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    table = new JTable(data, columnNames);
    frame.add(table);
    frame.pack();
}
 
Example 10
Source File: ColorDifference.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void createAndShowGUI() {
JFrame f = new JFrame("Color Difference");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 200);
ColorDifference component = new ColorDifference();
f.add(component);
       f.pack();
f.setVisible(true);
   }
 
Example 11
Source File: Regression_142403_swing.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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_142403_swing siv = new Regression_142403_swing( );

	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 File: MainMenu.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Run the menu app
 *
 * @param args
 */
public static void main(String[] args) {
	final JFrame f = new JFrame();
	final MainMenu mm = new MainMenu();
	f.getContentPane().add(mm);
	f.setSize(800, 600);
	f.setLocationRelativeTo(null);
	// mm.tabs.setSelectedIndex(1);
	mm.tabs.setSelectedIndex(0);
	f.setVisible(true);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
Example 13
Source File: CustomCompositeTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void initGUI() {
    frame = new JFrame("Silly composite");
    frame.getContentPane().add(new MyComp());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}
 
Example 14
Source File: Langton.java    From ThinkJavaCode2 with MIT License 5 votes vote down vote up
/**
 * Creates and runs the simulation.
 * 
 * @param args command-line arguments
 */
public static void main(String[] args) {
    String title = "Langton's Ant";
    Langton game = new Langton(61, 61);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.add(game.grid);
    frame.pack();
    frame.setVisible(true);
    game.mainloop();
}
 
Example 15
Source File: Win1.java    From CPE552-Java with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setSize(600,500);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    
}
 
Example 16
Source File: bug8016356.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowUI() {
    frame = new JFrame();
    frame.setBounds(10, scrTop + 10, 300, 100);
    JPanel panel = new JPanel();
    panel.setBackground(color);
    frame.getContentPane().add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 17
Source File: GenealogyExample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("GenealogyExample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    GenealogyExample newContentPane = new GenealogyExample();
    newContentPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(newContentPane);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
}
 
Example 18
Source File: Demo5.java    From jexer with MIT License 4 votes vote down vote up
/**
 * Run two demo applications in separate panes.
 */
private void addApplications() {

    /*
     * In this demo we will create two swing panels with two
     * independently running applications, each with a different font
     * size.
     */

    /*
     * First we create a panel to put it on.  We need this to pass to
     * SwingBackend's constructor, so that it knows not to create a new
     * frame.
     */
    JPanel app1Panel = new JPanel();

    /*
     * Next, we create the Swing backend.  The "listener" (second
     * argument, set to null) is what the backend wakes up on every event
     * received.  Typically this is the TApplication.  TApplication sets
     * it in its constructor, so we can pass null here and be fine.
     */
    SwingBackend app1Backend = new SwingBackend(app1Panel, null,
        80, 25, 16);
    // Now that we have the backend, construct the TApplication.
    app1 = new DemoApplication(app1Backend);

    /*
     * The second panel is the same sequence, except that we also change
     * the font from the default Terminus to JVM monospaced.
     */
    JPanel app2Panel = new JPanel();
    SwingBackend app2Backend = new SwingBackend(app2Panel, null,
        80, 25, 18);
    app2 = new DemoApplication(app2Backend);
    Font font = new Font(Font.MONOSPACED, Font.PLAIN, 18);
    app2Backend.setFont(font);

    /*
     * Now that the applications are ready, spin them off on their
     * threads.
     */
    (new Thread(app1)).start();
    (new Thread(app2)).start();

    /*
     * The rest of this is standard Swing.  Set up a frame, a split pane,
     * put each of the panels on it, and make it visible.
     */
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(this);
    JSplitPane mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
        app1Panel, app2Panel);
    mainPane.setOneTouchExpandable(true);
    mainPane.setDividerLocation(500);
    mainPane.setDividerSize(6);
    mainPane.setBorder(null);
    frame.setContentPane(mainPane);

    frame.setTitle("Two Jexer Apps In One Swing UI");
    frame.setSize(1000, 640);
    frame.setVisible(true);
}
 
Example 19
Source File: Main.java    From blog with Apache License 2.0 4 votes vote down vote up
public void createAndShowUI() {
	BoundedRangeModel progressModel = new DefaultBoundedRangeModel();
	BoundedRangeProgress progressAdapter = new BoundedRangeProgress(progressModel);
	Document resultDocument = new PlainDocument();

	ComponentVisibility progressBarVisibility = new ComponentVisibility("enabled", false);
	progressBarVisibility.setInvisibleDelay(1, TimeUnit.SECONDS);

	ProgressCancelAction cancelAction = new ProgressCancelAction();
	cancelAction.putValue(Action.NAME, "Cancel");

	ProgressSimulationAction progressAction = new ProgressSimulationAction();
	progressAction.addProgressAware(progressAdapter);
	progressAction.addProgressAware(cancelAction);
	progressAction.addPropertyChangeListener(progressBarVisibility);
	progressAction.putValue(Action.NAME, "Start");
	progressAction.setResultDocument(resultDocument);

	JFrame mainFrame = new JFrame("Progress Object Pattern with Java Swing");
	mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	mainFrame.setMinimumSize(new Dimension(600, 120));

	JProgressBar progressBar = new JProgressBar(progressModel);
	progressBar.setVisible(false);
	progressBar.setStringPainted(true);
	progressBarVisibility.setComponent(progressBar);

	JButton startProgressButton = new JButton(progressAction);
	JButton cancelButton = new JButton(cancelAction);
	JTextField resultTextField = new JTextField(40);
	resultTextField.setEditable(false);
	resultTextField.setDocument(resultDocument);

	JPanel mainPanel = new JPanel();
	mainPanel.add(startProgressButton);
	mainPanel.add(cancelButton);
	mainPanel.add(resultTextField);

	Container contentPane = mainFrame.getContentPane();
	contentPane.add(mainPanel);
	contentPane.add(progressBar, BorderLayout.SOUTH);

	mainFrame.pack();
	mainFrame.setLocationRelativeTo(null);
	mainFrame.setVisible(true);
}
 
Example 20
Source File: DemoUtil.java    From littleluck with Apache License 2.0 3 votes vote down vote up
public static JFrame createFrame(String title, int w, int h)
{
    JFrame frame = new JFrame(title);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(w, h);

    return frame;
}