javax.swing.JFrame#setDefaultCloseOperation ( )源码实例Demo

下面列出了javax.swing.JFrame#setDefaultCloseOperation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u_jdk   文件: Test8015926.java
@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);
}
 
源代码2 项目: moa   文件: CDTaskManagerPanel.java
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);
    }
 
源代码3 项目: moa   文件: MultiLabelTaskManagerPanel.java
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);
    }
 
源代码4 项目: openjdk-jdk8u   文件: bug8136998.java
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);
}
 
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();
}
 
源代码6 项目: marathonv5   文件: GenealogyExample.java
/**
 * 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);
}
 
源代码7 项目: ThinkJavaCode2   文件: Langton.java
/**
 * 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();
}
 
源代码8 项目: CodenameOne   文件: RetroWeaverGui.java
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);
}
 
源代码9 项目: jdk8u-jdk   文件: bug7170310.java
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);
}
 
源代码10 项目: jdk8u_jdk   文件: LinearGradientPrintingTest.java
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);
}
 
源代码11 项目: ET_Redux   文件: BasicDnD.java
/**
 * 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);
}
 
源代码12 项目: filthy-rich-clients   文件: ColorDifference.java
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);
   }
 
源代码13 项目: birt   文件: Regression_142403_swing.java
/**
 * 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 );
}
 
源代码14 项目: COMP6237   文件: MainMenu.java
/**
 * 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);
}
 
源代码15 项目: jdk8u60   文件: CustomCompositeTest.java
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);
}
 
源代码16 项目: CPE552-Java   文件: Win1.java
public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setSize(600,500);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    
}
 
源代码17 项目: jdk8u-dev-jdk   文件: bug8016356.java
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);
}
 
源代码18 项目: jexer   文件: Demo5.java
/**
 * 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);
}
 
源代码19 项目: blog   文件: Main.java
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);
}
 
源代码20 项目: littleluck   文件: DemoUtil.java
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;
}