Java 8 Frame - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Frame class.

This code example shows how to use the following methods:add, setLayout
        c.add(new Button("south"), BorderLayout.SOUTH);
        c.add(new Button("east"), BorderLayout.EAST);
        c.add(new Button("west"), BorderLayout.WEST);
        c.add(comp, BorderLayout.CENTER);
 
        f.setLayout(new BorderLayout());
        f.add(new Button("NORTH"), BorderLayout.NORTH);
        f.add(new Button("SOUTH"), BorderLayout.SOUTH);
        f.add(new Button("EAST"), BorderLayout.EAST);
        f.add(new Button("WEST"), BorderLayout.WEST);
        f.add(c, BorderLayout.CENTER);
 
        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
            public void run() { 
                f.pack();
                f.validate();
                f.setVisible(true);
            }}); 
    } 
 
7
CodeRank
This code example shows how to use the following methods:setResizable, pack, setVisible, setDefaultCloseOperation, add
		panel.setFPSDisplayed(true);
		panel.setDisplayDebugInfo(true);
		panel.setImageSizeDisplayed(true);
		panel.setMirrored(true);
 
		JFrame window = new JFrame("Test webcam panel");
		window.add(panel);
		window.setResizable(true);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.pack();
		window.setVisible(true);
	} 
} 
7
CodeRank
This code example shows how to use the following methods:validate, setSize, sleep, add
        final GLProfile glprofile = GLProfile.getDefault(); 
        final GLCapabilities glCapabilities = new GLCapabilities(glprofile); 
        final GLCanvas canvas = new GLCanvas(glCapabilities); 
        canvas.addGLEventListener( this ); 
 
        final Frame frame = new Frame("Test"); 
        frame.add(canvas); 
        frame.setSize(256, 256); 
        frame.validate(); 
 
        try { 
            javax.swing.SwingUtilities.invokeAndWait(new Runnable() { 
                public void run() { 
                    frame.setVisible(true); 
                }}); 
        } catch (final Throwable t) { 
            t.printStackTrace(); 
            Assume.assumeNoException(t); 
        } 
 

7
CodeRank
This code example shows how to use the following methods:setResizable, pack, setVisible, setDefaultCloseOperation, add
		Webcam webcam = Webcam.getDefault();
 
		WebcamPanel panel = new WebcamPanel(webcam);
		panel.setFPSDisplayed(true);
 
		JFrame window = new JFrame("Test webcam panel");
		window.add(panel);
		window.setResizable(false);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.pack();
		window.setVisible(true);
	} 
} 
7
CodeRank
This code example shows how to use the following methods:setUndecorated, dispose, setBounds, setVisible, sleep
 
public class IAEforEmptyFrameTest { 
    public static void main(String[] args) {
        JFrame f = null;
        try { 
            f = new JFrame("IAEforEmptyFrameTest");
            f.setUndecorated(true);
            f.setBounds(100, 100, 320, 240);
            f.setVisible(true);
            try { Thread.sleep(1000); } catch (Exception z) {}
            f.setBounds(0, 0, 0, 0);
            try { Thread.sleep(1000); } catch (Exception z) {}
            f.dispose();
        } finally { 
            f.dispose();
        }; 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:add, setExtendedState, pack, setVisible
 
import test.java.awt.regtesthelpers.Util; 
 
public class FrameMinimizeTest { 
    public static void main(String args[]) throws Exception {
        Frame frame = new Frame("Frame Minimize Test");
        Button b = new Button("Focus ownder");
        frame.add("South", b);
        frame.pack();
        frame.setVisible(true);
        Util.waitForIdle(null); 
        if (!b.hasFocus()) {
            throw new RuntimeException("button is not a focus owner after showing :(");
        } 
        frame.setExtendedState(Frame.ICONIFIED);
        Util.waitForIdle(null); 
        frame.setExtendedState(Frame.NORMAL);
        Util.waitForIdle(null); 
        if (!b.hasFocus()) {
            throw new RuntimeException("button is not a focus owner after restoring :(");

7
CodeRank
This code example shows how to use the following methods:getHeight, getLocation, getWidth
        getContentPane().add("South", buttonPanel);
    } 
     
    public void setVisible(boolean visible) {
        if (visible) {
            setLocation((int) frame.getLocation().getX() + (frame.getWidth() / 2) - (getWidth() / 2), 
                    (int) frame.getLocation().getY() + (frame.getHeight() / 2) - (getHeight() / 2));
        } 
         
        super.setVisible(visible);
    } 
 
    @Override 
    public void actionPerformed(ActionEvent e) {
        setVisible(false); 
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:setResizable, pack, setVisible, setDefaultCloseOperation, add
		WebcamPanel panel = new WebcamPanel(webcam);
		panel.setFPSDisplayed(true);
		panel.setImageSizeDisplayed(true);
		panel.setMirrored(false);
 
		JFrame window = new JFrame("Dummy Device Example");
		window.add(panel);
		window.setResizable(true);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.pack();
		window.setVisible(true);
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:add, setLayout, dispose, pack, setVisible
import test.java.awt.regtesthelpers.Util; 
 
public class RequestFocusAndHideTest { 
    public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
    { 
        final Frame frame = new Frame("the test");
        frame.setLayout(new FlowLayout());
        final Button btn1 = new Button("button 1");
        frame.add(btn1);
        frame.add(new Button("button 2"));
        frame.add(new Button("button 3"));
        frame.pack();
        frame.setVisible(true);
 
        Robot r = Util.createRobot();
        Util.waitForIdle(r);
        Util.clickOnComp(btn1, r);
        Util.waitForIdle(r);
        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        if (kfm.getFocusOwner() != btn1) {

6
CodeRank
This code example shows how to use the following methods:validate, remove, add
            }}); 
        Thread.sleep(durationPerTest/2);
 
        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
            public void run() { 
                frame.remove(glCanvas);
                frame.validate();
                frame.add(glCanvas);
                frame.validate();
            }}); 
        Thread.sleep(durationPerTest/2);
 
        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
            public void run() { 
                glCanvas.destroy();
                frame.dispose();
            }}); 
 
        animator.stop();
    } 
6
CodeRank
See Code Examples for Java 8 Frame Methods: