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

The following examples show how to use javax.swing.JFrame#setDefaultCloseOperation() . 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
@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
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
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 4
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 5
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 6
Source Project: marathonv5   File: GenealogyExample.java    License: 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 7
Source Project: ThinkJavaCode2   File: Langton.java    License: 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 8
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 9
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 10
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 11
Source Project: ET_Redux   File: BasicDnD.java    License: 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 12
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 13
/**
 * 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 14
/**
 * 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 15
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 16
Source Project: CPE552-Java   File: Win1.java    License: 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 17
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 18
Source Project: jexer   File: Demo5.java    License: 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 Project: blog   File: Main.java    License: 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 Project: littleluck   File: DemoUtil.java    License: 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;
}