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

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

源代码1 项目: filthy-rich-clients   文件: Triggers.java
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);
}
 
源代码2 项目: radiance   文件: GetCurrentSkin.java
/**
 * 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();
}
 
源代码3 项目: filthy-rich-clients   文件: RaceGUI.java
/**
 * 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);
}
 
源代码4 项目: TinkerTime   文件: TinkerTimeLauncher.java
@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();
}
 
源代码5 项目: haxademic   文件: VirtualCursor.java
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();
}
 
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);
}
 
源代码7 项目: incubator-batchee   文件: DiagramGenerator.java
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;
}
 
源代码8 项目: marathonv5   文件: AnnotateScreenCapture.java
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;
}
 
源代码9 项目: MikuMikuStudio   文件: RayTrace.java
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);
}
 
源代码10 项目: dctb-utfpr-2018-1   文件: JToggleButtonDemo.java
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);
    }
 
源代码11 项目: GIFKR   文件: DebugUtils.java
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);
}
 
源代码12 项目: openjdk-jdk9   文件: ComponentResizeTest.java
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);
}
 
源代码13 项目: PyramidShader   文件: RotatedLabel.java
/**
 * 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);
}
 
源代码14 项目: gpu-nbody   文件: NBodyVisualizer.java
/**
 * 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();

}
 
源代码15 项目: training   文件: Undoner.java
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();
	}
 
源代码16 项目: Pixie   文件: ImagePanel.java
/**
 * 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);
}
 
源代码17 项目: openjdk-jdk9   文件: WrongEditorTextFieldFont.java
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));
    }
}
 
源代码18 项目: dctb-utfpr-2018-1   文件: Sliders.java
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);

}
 
源代码19 项目: lwjgl3-awt   文件: Core32Test.java
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);
  }
 
源代码20 项目: openjdk-jdk9   文件: bug8033699.java
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();
}