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

The following examples show how to use javax.swing.JFrame#setLayout() . 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
private static void createAndShowGUI() {
    JFrame f = new JFrame("Triggers");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLayout(new BorderLayout());
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BorderLayout());
    // Note: "Other Button" exists only to provide another component to
    // move focus from/to, in order to show how FocusTrigger works
    buttonPanel.add(new JButton("Other Button"), BorderLayout.NORTH);
    triggerButton = new JButton("Trigger");
    buttonPanel.add(triggerButton, BorderLayout.SOUTH);
    f.add(buttonPanel, BorderLayout.NORTH);
    f.add(new Triggers(), BorderLayout.CENTER);
    f.pack();
    f.setVisible(true);
}
 
Example 2
/**
 * Opens a sample frame under the specified skin.
 * 
 * @param skin
 *            Skin.
 */
private void openSampleFrame(SubstanceSkin skin) {
    final JFrame sampleFrame = new JFrame(skin.getDisplayName());
    sampleFrame.setLayout(new FlowLayout());
    final JButton button = new JButton("Get skin");
    button.addActionListener((ActionEvent e) -> SwingUtilities.invokeLater(
            () -> JOptionPane.showMessageDialog(sampleFrame, "Skin of this button is "
                    + SubstanceCortex.ComponentScope.getCurrentSkin(button).getDisplayName())));

    sampleFrame.add(button);

    sampleFrame.setVisible(true);
    sampleFrame.setSize(200, 100);
    sampleFrame.setLocationRelativeTo(null);
    sampleFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    SubstanceCortex.RootPaneScope.setSkin(sampleFrame.getRootPane(), skin);
    SwingUtilities.updateComponentTreeUI(sampleFrame);
    sampleFrame.repaint();
}
 
Example 3
/**
 * Creates a new instance of RaceGUI
 */
public RaceGUI(String appName) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JFrame f = new JFrame(appName);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLayout(new BorderLayout());
    
    // Add Track view
    track = new TrackView();
    f.add(track, BorderLayout.CENTER);
    
    // Add control panel
    controlPanel = new RaceControlPanel();
    f.add(controlPanel, BorderLayout.SOUTH);
    
    f.pack();
    f.setVisible(true);
}
 
Example 4
@Override
public void run() {
	// Get App Icons
	ImageManager imageManager = new ImageManager();
	List<Image> appIcons = new ArrayList<Image>();
	appIcons.add(imageManager.getImage("icon/app/icon 128x128.png"));
	appIcons.add(imageManager.getImage("icon/app/icon 64x64.png"));
	appIcons.add(imageManager.getImage("icon/app/icon 32x32.png"));
	appIcons.add(imageManager.getImage("icon/app/icon 16x16.png"));

	// Hide Splash Screen so the JFrame does not hide when appearing
	SplashScreen s = SplashScreen.getSplashScreen();
	if (s != null){
		s.close();
	}

	// Initialize Frame
	JFrame frame = new JFrame(TinkerTimeLauncher.FULL_NAME);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setLayout(new BorderLayout());
	frame.setIconImages(appIcons);
	frame.setJMenuBar(menuBar);
	frame.add(toolBar, BorderLayout.NORTH);
	frame.add(modSelectorPanelController.getComponent(), BorderLayout.CENTER);
	frame.pack();
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
	frame.toFront();
}
 
Example 5
Source Project: haxademic   File: VirtualCursor.java    License: MIT License 5 votes vote down vote up
public void setup() {
	super.setup();

	fxPanel = new JFXPanel();

	jframe = (JFrame)((PSurfaceAWT.SmoothCanvas) getSurface().getNative()).getFrame();
	jframe.removeNotify();
	jframe.setUndecorated(true);
	jframe.setLayout(null);
	jframe.addNotify();
	jframe.setAlwaysOnTop(true);
	jframe.add(fxPanel);
	jframe.setSize(750, 900);
	jframe.setVisible(true);
	jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	Platform.runLater(new Runnable() {
		@Override
		public void run() {
			initFX(fxPanel);
		}
	});
	// set special window properties
	jframe.setContentPane(fxPanel);
	fxPanel.setFocusable(false);
	fxPanel.setFocusTraversalKeysEnabled(false);
	fxPanel.requestFocus();
	fxPanel.requestFocusInWindow();
}
 
Example 6
public static void constructTestUI() {
    myFrame = new JFrame();
    myFrame.setLayout(new BorderLayout());
    myButton = new JButton("Whatever");
    myFrame.add(myButton, BorderLayout.CENTER);
    myFrame.setSize(400, 300);
    myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    myFrame.setVisible(true);
}
 
Example 7
private JFrame createWindow(final VisualizationViewer<Node, Edge> viewer, final String name) {
    viewer.setBackground(Color.WHITE);

    final DefaultModalGraphMouse<Node, Edge> gm = new DefaultModalGraphMouse<Node, Edge>();
    gm.setMode(DefaultModalGraphMouse.Mode.PICKING);
    viewer.setGraphMouse(gm);

    final JFrame frame = new JFrame(name + " viewer");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setLayout(new GridLayout());
    frame.getContentPane().add(viewer);
    frame.pack();

    return frame;
}
 
Example 8
public File saveToFile(File captureFile) throws FileNotFoundException, IOException {
    writePNG(captureFile);

    ImageReader reader = getPNGImageReader();
    ImageInputStream iis = ImageIO.createImageInputStream(new FileInputStream(captureFile));
    reader.setInput(iis);
    BufferedImage pngImage = reader.read(0);
    IIOMetadata imageMetadata = reader.getImageMetadata(0);

    Node root = imageMetadata.getAsTree(imageMetadata.getNativeMetadataFormatName());
    IIOMetadataNode textNode = new IIOMetadataNode("tEXt");
    ArrayList<Annotation> annotations = imagePanel.getAnnotations();
    for (int i = 0; i < annotations.size(); i++) {
        textNode.appendChild(getAnnotationNode((Annotation) annotations.get(i), i));
    }
    root.appendChild(textNode);

    imageMetadata.mergeTree(imageMetadata.getNativeMetadataFormatName(), root);

    IIOImage imageWrite = new IIOImage(pngImage, new ArrayList<BufferedImage>(), imageMetadata);

    ImageWriter writer = getPNGImageWriter();
    ImageOutputStream ios = ImageIO.createImageOutputStream(new FileOutputStream(captureFile));
    writer.setOutput(ios);
    writer.write(imageWrite);
    writer.dispose();

    JFrame frame = new JFrame();
    frame.setLayout(new BorderLayout());
    ImagePanel finalImage = new ImagePanel(new FileInputStream(captureFile), false);
    frame.add(finalImage, BorderLayout.CENTER);
    frame.pack();
    File savedFile = new File(captureFile.getParentFile(), "ext-" + captureFile.getName());
    getScreenShot(frame.getContentPane(), savedFile);
    frame.dispose();

    return savedFile;
}
 
Example 9
public void show(){
    frame = new JFrame("HDR View");
    label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label);
    frame.setLayout(new FlowLayout());
    frame.pack();
    frame.setVisible(true);
}
 
Example 10
JToggleButtonDemo() {

        //CRIA UM CONTEINER JFRAME
        JFrame jfrm = new JFrame(" EXEMPLO DE JToggleButton - botão de alternância");

        //ESPECIFICA FLOWLAYOUT COMO GERENCIADOR DE LEIAUTE
        jfrm.setLayout(new FlowLayout());

        //FORNECE UM TAMANHO INICIAL PAR AO QUADRO
        jfrm.setSize(250, 100);

        //ENCERRA O PROGRAMA QUANDO O USUÁRIO FECHA O APLICATIVO
        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //CRIA UM RÓTULO
        jlab = new JLabel(" O BOTÃO NÃO ESTÁ SELECIONADO ");

        //CRIA UM BOTÃO DE ALTERNÂNCIA
        jtbn = new JToggleButton("On/Off");

        // ADICIONA UM OUVINTE DE ITENS PARA O BOTÃO DE ALTERNÂNCIA
        //USA UM ITEM LISTENER PARA TRATAR EVENTOS DO BOTÃO DE ALTERNÂNCIA
        //USA IS SELECTED() PARA DETERMINAR O ESTADO DO BOTÃO
        jtbn.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent ie) {
                if (jtbn.isSelected()) {
                    jlab.setText(" O BOTÃO ESTÁ SELECIONADO" );
                } else {
                    jlab.setText(" O BOTÃO NÃO ESTÁ SELECIONADO.");
                }
            }
        });

        // ADICIONA O BOTÃO DE ALTERNÂNCIA E O RÓTULO AO PAINEL DE CONTEÚDO
        jfrm.add(jtbn);
        jfrm.add(jlab);

        // Display the frame.
        jfrm.setVisible(true);
    }
 
Example 11
public static void displayImage(Image img) {
	JFrame f = new JFrame("DEBUG IMG");
	
	JLabel label = new JLabel(new ImageIcon(img));
	label.setBorder(BorderFactory.createLineBorder(Color.RED));
	f.setLayout(new BorderLayout());
	f.add(label, BorderLayout.WEST);
	f.pack();
	f.setVisible(true);
	f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
 
Example 12
private static void createAndShowGUI() {
    demoFrame = new JFrame();
    demoFrame.setSize(300, 300);
    demoFrame.setLayout(new FlowLayout());
    demoFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    demoFrame.setUndecorated(true);
    demoFrame.setBackground(new Color(0f, 0, 0, 0.1f));
    JCheckBox b = new JCheckBox("Whatever");
    demoFrame.paintAll(null);
    b.setOpaque(true);
    demoFrame.add(b);
    demoFrame.add(new JButton());
    demoFrame.setVisible(true);
}
 
Example 13
/**
 * Test method.
 * 
 * @param args
 *          command line arguments.
 */
public static void main(String[] args) {
  JFrame f = new JFrame("Test");
  f.setLayout(new FlowLayout());
  RotatedLabel rl = new RotatedLabel("BLAHBLAH");
  rl.setBackground(Color.ORANGE);
  rl.setOpaque(true);
  rl.setDirection(Direction.VERTICAL_DOWN);
  f.add(rl);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.pack();
  f.setVisible(true);
}
 
Example 14
Source Project: gpu-nbody   File: NBodyVisualizer.java    License: MIT License 4 votes vote down vote up
/**
 * Creates a new JOCLSimpleGL3 sample.
 * 
 * @param capabilities
 *            The GL capabilities
 */
public NBodyVisualizer(final GLCapabilities capabilities) {
	glComponent = new GLCanvas(capabilities);
	glComponent.setFocusable(true);
	glComponent.addGLEventListener(this);

	// Initialize the mouse and keyboard controls
	final MouseControl mouseControl = new MouseControl();
	glComponent.addMouseMotionListener(mouseControl);
	glComponent.addMouseWheelListener(mouseControl);
	final KeyboardControl keyboardControl = new KeyboardControl();
	glComponent.addKeyListener(keyboardControl);

	setFullscreen();

	updateModelviewMatrix();

	// Create and start an animator
	animator = new Animator(glComponent);
	animator.start();

	// Create the simulation
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new SerializedUniverseGenerator("universes/sphericaluniverse1.universe"));
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new SerializedUniverseGenerator("universes/montecarlouniverse1.universe"));

	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new RotatingDiskGalaxyGenerator(3.5f, 25, 0));
	simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new RotatingDiskGalaxyGenerator(3.5f, 1, 1));
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new SphericalUniverseGenerator());
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new LonLatSphericalUniverseGenerator());

	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new RandomCubicUniverseGenerator(5));
	// simulation = new GPUBarnesHutNBodySimulation(Mode.GL_INTEROP, 2048 * 16, new MonteCarloSphericalUniverseGenerator());

	// simulation = new GpuNBodySimulation(Mode.GL_INTEROP, 2048 * 8, new LonLatSphericalUniverseGenerator());
	// simulation = new GpuNBodySimulation(Mode.GL_INTEROP, 2048, new PlummerUniverseGenerator());
	// simulation = new GpuNBodySimulation(Mode.GL_INTEROP, 128, new SphericalUniverseGenerator());

	// Create the main frame
	frame = new JFrame("NBody Simulation");
	frame.addWindowListener(new WindowAdapter() {
		@Override
		public void windowClosing(final WindowEvent e) {
			runExit();
		}
	});
	frame.setLayout(new BorderLayout());
	frame.add(glComponent, BorderLayout.CENTER);

	frame.setUndecorated(true);
	frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
	frame.setVisible(true);
	frame.setLocationRelativeTo(null);
	glComponent.requestFocus();

}
 
Example 15
Source Project: training   File: Undoner.java    License: MIT License 4 votes vote down vote up
public static void main(String[] args) throws IOException {
		List<String> projects = searchUndoableProjects();
		
		
		JFrame frame = new JFrame();
		frame.setSize(300, 150);
		frame.setLayout(new BorderLayout());
//		
//		JCheckBox cleanFolder = new JCheckBox("Clean destination folder", isVictorMachine());
//		if (isVictorMachine()) {
//			cleanFolder.setEnabled(false);
//		}
//		frame.add(cleanFolder, BorderLayout.NORTH);
		JPanel panel2 = new JPanel();
		panel2.setLayout(new BorderLayout());
		JComboBox<String> projectsCombo = new JComboBox<>(projects.stream().sorted().collect(toList()).toArray(new String[0]));
		panel2.add(projectsCombo, BorderLayout.CENTER);
		panel2.add(new JLabel("Revert solution for project:"), BorderLayout.NORTH);
		final JCheckBox clearEntityAnnotations = new JCheckBox("Clear Entity annotations");
		panel2.add(clearEntityAnnotations, BorderLayout.SOUTH);
		frame.add(panel2, BorderLayout.CENTER);
		JButton button = new JButton("UNDO ("+(isVictorMachine()?"Victor":"Trainee") +")");
		frame.add(button, BorderLayout.SOUTH);
		
		button.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
//				if (cleanFolder.isSelected()) {
//					cleanDestFolder();
//				}
				File inputSrcFolder = new File(getFolderContainingTheProjects(), projectsCombo.getSelectedItem() + "");// + "/src/main");
				boolean undone;
				if (isVictorMachine()) {
					try {
						FileUtils.copyDirectoryToDirectory(inputSrcFolder, new File("../../training-undone/"));
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
					File rootToUndone = new File("../../training-undone/"+projectsCombo.getSelectedItem());
					undone = undoFolders(rootToUndone, rootToUndone, false, clearEntityAnnotations.isSelected());
				} else {
					undone = undoFolders(inputSrcFolder, inputSrcFolder, false, clearEntityAnnotations.isSelected());
				}
				JOptionPane.showMessageDialog(null, undone ? "Undone. Good luck!\n\nRemember: To see the solved version, HARD reset your worspace." : "Nothing to undo (already undone?)");
			}
		});
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		frame.setLocation(dim.width/2-frame.getSize().width/2, dim.height/2-frame.getSize().height/2);
		frame.setTitle("Revert solution for project...");
		frame.show();
	}
 
Example 16
Source Project: Pixie   File: ImagePanel.java    License: MIT License 4 votes vote down vote up
/**
 * The entry point of application.
 *
 * @param args the input arguments
 */
public static void main(String[] args) {
    // create the panel with the image
    ImagePanel imgPanel = new ImagePanel(Icons.SPLASH_SCREEN_PATH);

    // create the frame which will display the panel        
    JFrame frame = new JFrame("Image Panel Preview");

    frame.setLayout(new FlowLayout());

    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    imgPanel.setPanelTitle("Pixie", new int[]{15, 5, 5, 5});

    // add the panel to the frame
    frame.add(imgPanel);

    // prepare frame for display
    frame.pack();

    frame.setLocationRelativeTo(null);

    frame.setVisible(true);
}
 
Example 17
private static void testDefaultFont(final JFrame frame) {
    final JSpinner spinner = new JSpinner();
    final JSpinner spinner_u = new JSpinner();
    frame.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 50));
    frame.getContentPane().add(spinner);
    frame.getContentPane().add(spinner_u);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    final DefaultEditor ed = (DefaultEditor) spinner.getEditor();
    final DefaultEditor ed_u = (DefaultEditor) spinner_u.getEditor();
    ed_u.getTextField().setFont(USERS_FONT);

    for (int i = 5; i < 40; i += 5) {
        /*
         * Validate that the font of the text field is changed to the
         * font of JSpinner if the font of text field was not set by the
         * user.
         */
        final Font tff = ed.getTextField().getFont();
        if (!(tff instanceof UIResource)) {
            throw new RuntimeException("Font must be UIResource");
        }
        if (spinner.getFont().getSize() != tff.getSize()) {
            throw new RuntimeException("Rrong size");
        }
        spinner.setFont(new Font("dialog", Font.BOLD, i));
        /*
         * Validate that the font of the text field is NOT changed to the
         * font of JSpinner if the font of text field was set by the user.
         */
        final Font tff_u = ed_u.getTextField().getFont();
        if (tff_u instanceof UIResource || !tff_u.equals(USERS_FONT)) {
            throw new RuntimeException("Font must NOT be UIResource");
        }
        if (spinner_u.getFont().getSize() == tff_u.getSize()) {
            throw new RuntimeException("Wrong size");
        }
        spinner_u.setFont(new Font("dialog", Font.BOLD, i));
    }
}
 
Example 18
Source Project: dctb-utfpr-2018-1   File: Sliders.java    License: Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	// Create and set up a frame window
	JFrame.setDefaultLookAndFeelDecorated(true);
	JFrame frame = new JFrame("Slider with change listener");
	frame.setSize(500, 500);
	frame.setLayout(new GridLayout(3, 1));
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	// Set the panel to add buttons
	JPanel panel1 = new JPanel();
	JPanel panel2 = new JPanel();
	
	// Add status label to show the status of the slider
	JLabel status = new JLabel("Slide the slider and you can get its value", JLabel.CENTER);
	
	// Set the slider
	JSlider slider = new JSlider();	
	slider.setMinorTickSpacing(10);
	slider.setPaintTicks(true);
	
	// Set the labels to be painted on the slider
	slider.setPaintLabels(true);
	
	// Add positions label in the slider
	Hashtable<Integer, JLabel> position = new Hashtable<Integer, JLabel>();
	position.put(0, new JLabel("0"));
	position.put(50, new JLabel("50"));
	position.put(100, new JLabel("100"));
	
	// Set the label to be drawn
	slider.setLabelTable(position);
	
	// Add change listener to the slider
	slider.addChangeListener(new ChangeListener() {
		public void stateChanged(ChangeEvent e) {
			status.setText("Value of the slider is: " + ((JSlider)e.getSource()).getValue());
		}
	});
	
	// Add the slider to the panel
	panel1.add(slider);
	
	// Set the window to be visible as the default to be false
	frame.add(panel1);
	frame.add(status);
	frame.add(panel2);
	frame.pack();
	frame.setVisible(true);

}
 
Example 19
Source Project: lwjgl3-awt   File: Core32Test.java    License: MIT License 4 votes vote down vote up
public static void main(String[] args) {
      JFrame frame = new JFrame("AWT test");
      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      frame.setLayout(new BorderLayout());
      frame.setPreferredSize(new Dimension(600, 600));
      GLData data = new GLData();
      data.samples = 4;
      data.swapInterval = 0;
      data.majorVersion = 3;
      data.minorVersion = 2;
      data.profile = GLData.Profile.CORE;
      AWTGLCanvas canvas;
      frame.add(canvas = new AWTGLCanvas(data) {
          private static final long serialVersionUID = 1L;
          int aspectUniform;
          public void initGL() {
              System.out.println("OpenGL version: " + effective.majorVersion + "." + effective.minorVersion + " (Profile: " + effective.profile + ")");
              createCapabilities();
              glClearColor(0.3f, 0.4f, 0.5f, 1);
              glBindVertexArray(glGenVertexArrays());
              int vbo = glGenBuffers();
              glBindBuffer(GL_ARRAY_BUFFER, vbo);
              glBufferData(GL_ARRAY_BUFFER, new float[] { -0.5f, 0, 0, -0.5f, 0.5f, 0, 0.5f, 0, 0, 0.5f, -0.5f, 0 }, GL_STATIC_DRAW);
              glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0L);
              glEnableVertexAttribArray(0);
              int vs = glCreateShader(GL_VERTEX_SHADER);
              glShaderSource(vs, "#version 150 core\nuniform float aspect;in vec2 vertex;void main(void){gl_Position=vec4(vertex/vec2(aspect, 1.0), 0.0, 1.0);}");
              glCompileShader(vs);
              if (glGetShaderi(vs, GL_COMPILE_STATUS) == 0)
                  throw new AssertionError("Could not compile vertex shader: " + glGetShaderInfoLog(vs));
              int fs = glCreateShader(GL_FRAGMENT_SHADER);
              glShaderSource(fs, "#version 150 core\nout vec4 color;void main(void){color=vec4(0.4, 0.6, 0.8, 1.0);}");
              glCompileShader(fs);
              if (glGetShaderi(fs, GL_COMPILE_STATUS) == 0)
                  throw new AssertionError("Could not compile fragment shader: " + glGetShaderInfoLog(fs));
              int prog = glCreateProgram();
              glAttachShader(prog, vs);
              glAttachShader(prog, fs);
              glLinkProgram(prog);
              if (glGetProgrami(prog, GL_LINK_STATUS) == 0)
                  throw new AssertionError("Could not link program: " + glGetProgramInfoLog(prog));
              glUseProgram(prog);
              aspectUniform = glGetUniformLocation(prog, "aspect");
          }
          public void paintGL() {
              int w = getWidth();
              int h = getHeight();
              float aspect = (float) w / h;
              glClear(GL_COLOR_BUFFER_BIT);
              glViewport(0, 0, w, h);
              glUniform1f(aspectUniform, aspect);
              glDrawArrays(GL_TRIANGLES, 0, 6);
              this.swapBuffers();
              this.repaint();
          }
      }, BorderLayout.CENTER);
      frame.pack();
      frame.setVisible(true);
      frame.transferFocus();

      Runnable renderLoop = new Runnable() {
	public void run() {
		if (!canvas.isValid())
			return;
		canvas.render();
		SwingUtilities.invokeLater(this);
	}
};
SwingUtilities.invokeLater(renderLoop);
  }
 
Example 20
private static void createAndShowGUI() {
    mainFrame = new JFrame("Bug 8033699 - 8 Tests for Grouped/Non Group Radio Buttons");
    btnStart = new JButton("Start");
    btnEnd = new JButton("End");
    btnMiddle = new JButton("Middle");

    JPanel box = new JPanel();
    box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
    box.setBorder(BorderFactory.createTitledBorder("Grouped Radio Buttons"));
    radioBtn1 = new JRadioButton("A");
    radioBtn2 = new JRadioButton("B");
    radioBtn3 = new JRadioButton("C");

    ButtonGroup btnGrp = new ButtonGroup();
    btnGrp.add(radioBtn1);
    btnGrp.add(radioBtn2);
    btnGrp.add(radioBtn3);
    radioBtn1.setSelected(true);

    box.add(radioBtn1);
    box.add(radioBtn2);
    box.add(btnMiddle);
    box.add(radioBtn3);

    radioBtnSingle = new JRadioButton("Not Grouped");
    radioBtnSingle.setSelected(true);

    mainFrame.getContentPane().add(btnStart);
    mainFrame.getContentPane().add(box);
    mainFrame.getContentPane().add(radioBtnSingle);
    mainFrame.getContentPane().add(btnEnd);

    mainFrame.getRootPane().setDefaultButton(btnStart);
    btnStart.requestFocus();

    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setLayout(new BoxLayout(mainFrame.getContentPane(), BoxLayout.Y_AXIS));

    mainFrame.setSize(300, 300);
    mainFrame.setLocation(200, 200);
    mainFrame.setVisible(true);
    mainFrame.toFront();
}