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

The following examples show how to use javax.swing.JFrame#add() . 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 showUI(){
  sFrame = new JFrame();

  JProgressBar progressBar = new JProgressBar();
  progressBar.setVisible(false);
  progressBar.setIndeterminate(false);
  progressBar.setIndeterminate(true);
  progressBar.setIndeterminate(false);
  progressBar.setValue(10);
  progressBar.setString("Progress");

  sFrame.add(progressBar);

  sProgressBar = new WeakReference<>(progressBar);

  sFrame.setSize(200,200);
  sFrame.setVisible(true);
}
 
Example 2
/**
 * 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 3
public static void main(String[] args) {

        final GLProfile gp = GLProfile.get(GLProfile.GL2);
        GLCapabilities cap = new GLCapabilities(gp);

        final GLCanvas gc = new GLCanvas(cap);
        JRotation jr = new JRotation();
        gc.addGLEventListener(jr);
        gc.setSize(400, 400);

        final JFrame frame = new JFrame("JOGL Rotation");

        frame.add(gc);
        frame.setSize(500, 400);
        frame.setVisible(true);

        final FPSAnimator animator = new FPSAnimator(gc, 400, true);
        animator.start();

    }
 
Example 4
protected void prepareControls() {
    frame = new JFrame("Mixing : Dropdown Overlapping test");
    frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
    frame.setSize(200, 200);
    frame.setVisible(true);

    cb = new JComboBox(petStrings);
    cb.setPreferredSize(new Dimension(frame.getContentPane().getWidth(), 20));
    cb.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == cb) {
                lwClicked = true;
            }
        }
    });

    frame.add(cb);
    propagateAWTControls(frame);
    frame.setVisible(true);
}
 
Example 5
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 6
/**
 *
 * @param args
 * @throws Exception
 */
public static void main ( String[] args ) throws Exception {

    JFrame testFrame = new JFrame();
    testFrame.setBounds( 400, 400, 600, 300 );
    testFrame.setDefaultCloseOperation( javax.swing.WindowConstants.EXIT_ON_CLOSE );

    ValueModel[] valueModels = new MineralStandardUPbRatioModel[5];
    for (int i = 0; i < 5; i ++) {
        valueModels[i] = new MineralStandardUPbRatioModel( "test " + i );
    }
    AbstractValueModelsPanelView testView = new MineralStandardUPbRatiosPanelViewNotEditable( valueModels);
    testView.setBorder( new LineBorder( Color.red ) );


    testFrame.add( testView );
    testFrame.setVisible( true );
}
 
Example 7
private static void showFrame(final TransformedPaintTest t) {
    JFrame f = new JFrame("TransformedPaintTest");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final BufferedImage bi =
        new BufferedImage(R_WIDTH, R_HEIGHT, BufferedImage.TYPE_INT_RGB);
    JPanel p = new JPanel() {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g;
            t.render(g2d, R_WIDTH, R_HEIGHT);
            t.render(bi.createGraphics(), R_WIDTH, R_HEIGHT);
            g2d.drawImage(bi, R_WIDTH + 5, 0, null);

            g.setColor(Color.black);
            g.drawString("Rendered to Back Buffer", 10, 20);
            g.drawString("Rendered to BufferedImage", R_WIDTH + 15, 20);
        }
    };
    p.setPreferredSize(new Dimension(2 * R_WIDTH + 5, R_HEIGHT));
    f.add(p);
    f.pack();
    f.setVisible(true);
}
 
Example 8
public ViewSetupExplorer( final AS data, final String xml, final X io )
{
	frame = new JFrame( "ViewSetup Explorer" );
	panel = new ViewSetupExplorerPanel< AS, X >( this, data, xml, io );

	frame.add( panel, BorderLayout.CENTER );
	frame.setSize( panel.getPreferredSize() );

	frame.addWindowListener(
			new WindowAdapter()
			{
				@Override
				public void windowClosing( WindowEvent evt )
				{
					quit();
				}
			});

	frame.pack();
	frame.setVisible( true );

	// set the initial focus to the table
	panel.table.requestFocus();
}
 
Example 9
public static void main(String[] args) {

        final GLProfile gp = GLProfile.get(GLProfile.GL2);
        GLCapabilities cap = new GLCapabilities(gp);

        final GLCanvas gc = new GLCanvas(cap);
        JLight tr = new JLight();
        gc.addGLEventListener(tr);
        gc.setSize(400, 400);

        final JFrame frame = new JFrame("JOGL Lighting");
        frame.add(gc);
        frame.setSize(500, 400);
        frame.setVisible(true);

        final FPSAnimator animator = new FPSAnimator(gc, 400, true);
        animator.start();
    }
 
Example 10
Source Project: diirt   File: VisualProfiler.java    License: MIT License 5 votes vote down vote up
/**
 * Makes a <code>JFrame</code> containing a <code>VisualProfiler</code>.
 * @return visible frame with a <code>VisualProfiler</code>
 */
public static JFrame makeFrame(){
        JFrame frame = new JFrame(FRAME_TITLE);
        frame.add(new VisualProfiler());
        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);  //Centers

        return frame;
}
 
Example 11
@Override
public void actionPerformed(ActionEvent e) {
	WorldModel tableModel = new WorldModel(world);
	JFrame frame = new JFrame("Buildings count: " + tableModel.getRowCount());
	
	JTable table = new JTable(tableModel);
	table.setBounds(50, 50, 400, 700);
	table.setAutoCreateRowSorter(true);
	table.getRowSorter().toggleSortOrder(1);
	frame.add(new JScrollPane(table));
	
	frame.setBounds(100,  100, 500, 800);
	frame.setVisible(true);
}
 
Example 12
private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInsertActionPerformed
    JFrame form = new JFrame();
    form.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    form.setTitle("Inserir");
    form.setResizable(false);
    form.setSize(new Dimension(347, 296));
    form.add(new PokemonPanelData(form));
    form.setVisible(true);
}
 
Example 13
public InterestPointExplorer( final String xml, final X io, final ViewSetupExplorer< AS, X > viewSetupExplorer )
{
	this.xml = xml;
	this.viewSetupExplorer = viewSetupExplorer;

	frame = new JFrame( "Interest Point Explorer" );
	panel = new InterestPointExplorerPanel( viewSetupExplorer.getPanel().getSpimData().getViewInterestPoints(), viewSetupExplorer );
	frame.add( panel, BorderLayout.CENTER );

	frame.setSize( panel.getPreferredSize() );

	frame.pack();
	frame.setVisible( true );
	
	// Get the size of the screen
	final Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

	// Move the window
	frame.setLocation( ( dim.width - frame.getSize().width ) / 2, ( dim.height - frame.getSize().height ) / 4 );

	// this call also triggers the first update of the registration table
	viewSetupExplorer.addListener( this );

	frame.addWindowListener( new WindowAdapter()
	{
		@Override
		public void windowClosing(WindowEvent e)
		{
			quit();
			e.getWindow().dispose();
		}
	});
}
 
Example 14
void initUI() {
    window = new JFrame("bug4337267");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setSize(800, 600);
    Component content = createContentPane();
    window.add(content);
    window.setVisible(true);
}
 
Example 15
public static void showFrame() {
     JFrame f = new JFrame();
     JTextArea jta = new JTextArea(info, 4, 30);
     jta.setLineWrap(true);
     jta.setWrapStyleWord(true);
     f.add("Center", jta);
     JButton b = new JButton("Print");
     b.addActionListener(testInstance);
     f.add("South", b);
     f.pack();
     f.setVisible(true);
}
 
Example 16
@Override
public void start() {

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent e) {
            System.err.println(e);
        }
    }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);

    boolean gained = false;
    final Robot robot = Util.createRobot();

    JFrame frame1 = new JFrame("Main Frame");
    final JButton b1 = new JButton("button1");
    frame1.add(b1);
    frame1.pack();
    frame1.setLocation(0, 300);

    Util.showWindowWait(frame1);

    final JFrame frame2 = new JFrame("Test Frame");
    final JButton b2 = new JButton("button2");
    frame2.add(b2);
    frame2.pack();
    frame2.setLocation(300, 300);

    b2.setEnabled(false);
    b2.requestFocus();

    Util.showWindowWait(frame2);

    robot.delay(500);

    //
    // It's expeced that the focus is restored to <button1>.
    // If not, click <button1> to set focus on it.
    //
    if (!b1.hasFocus()) {
        gained = Util.trackFocusGained(b1, new Runnable() {
            public void run() {
                Util.clickOnComp(b1, robot);
            }
        }, 5000, false);

        if (!gained) {
            throw new RuntimeException("Unexpected state: focus is not on <button1>");
        }
    }

    robot.delay(500);

    //
    // Click <button2>, check that focus is set on the parent frame.
    //
    gained = false;
    gained = Util.trackFocusGained(frame2, new Runnable() {
        public void run() {
            Util.clickOnComp(b2, robot);
        }
    }, 5000, false);

    if (!gained) {
        throw new RuntimeException("Test failed: focus wasn't set to <frame2>");
    }

    System.out.println("Test passed.");
}
 
Example 17
public static void main(String[] args) {
//    try {
//      UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
//    } catch (Exception e) {
//      // log.warn("Could not set the look and feel to nimbus.  "
//      // + "Hopefully you're on a mac so the window isn't ugly as crap.");
//    }
    TestbedModel model = new TestbedModel();
    final TestbedController controller =
        new TestbedController(model, UpdateBehavior.UPDATE_IGNORED, MouseBehavior.FORCE_Y_FLIP,
            new TestbedErrorHandler() {
              @Override
              public void serializationError(Exception e, String message) {
                JOptionPane.showMessageDialog(null, message, "Serialization Error",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
    JoglPanel panel = new JoglPanel(model, controller);
    model.setDebugDraw(new JoglDebugDraw(panel));
    model.setPanel(panel);
    TestList.populateModel(model);
    model.getSettings().getSetting(TestbedSettings.DrawWireframe).enabled = false;

    JFrame testbed = new JFrame();
    testbed.setTitle("JBox2D Testbed");
    testbed.setLayout(new BorderLayout());
    TestbedSidePanel side = new TestbedSidePanel(model, controller);
    testbed.add((Component) panel, "Center");
    testbed.add(new JScrollPane(side), "East");
    testbed.pack();
    testbed.setVisible(true);
    testbed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        controller.playTest(0);
        controller.start();
      }
    });
  }
 
Example 18
/**
 * Define the layout of components within the provided frame.
 *
 * @param frame the bare frame
 * @return the populated frame
 */
private JFrame defineLayout (JFrame frame)
{
    frame.setName("SampleBrowserFrame"); // For SAF life cycle

    // |- left --||-- center ---|--------------- right ---------------|
    //
    // +=========++=============+=====================================+
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . sheet . . | . . . . . . . . shape 1 pane. . . . |
    // | . . . . || . . . . . . | . . sample. . . . . . . . . . . . . |
    // | . . . . || . selector. | . . . . . . . . shape 2 pane. . . . |
    // | . . . . || . . . . . . | . . listing . . . . . . . . . . . . |
    // | . . . . ||=============| . . . . . . . . shape 3 pane. . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . sample. . |=====================================|
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . board . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | shape . ||-------------| . . . . . . . . . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | selector|| . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . eval. . . | . . . . sample. . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . board . . | . . . . context . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // | . . . . || . . . . . . | . . . . . . . . . . . . . . . . . . |
    // +=========++=============+=====================================+
    //
    // Left = shapeSelector
    shapeSelector.setName("shapeSelector");

    // Center
    BoardsPane boardsPane = new BoardsPane();
    boardsPane.addBoard(new SampleBoard(sampleController));
    boardsPane.addBoard(
            new SampleEvaluationBoard(sampleController, BasicClassifier.getInstance()));

    //        boardsPane.addBoard(
    //                new SampleEvaluationBoard(sampleController, DeepClassifier.getInstance()));
    //
    JSplitPane centerPane = new JSplitPane(
            VERTICAL_SPLIT,
            sheetSelector,
            boardsPane.getComponent());
    centerPane.setBorder(null);
    centerPane.setOneTouchExpandable(true);
    centerPane.setName("centerPane");

    // Right
    JSplitPane rightPane = new JSplitPane(
            VERTICAL_SPLIT,
            sampleListing,
            sampleContext.getComponent());
    rightPane.setBorder(null);
    rightPane.setOneTouchExpandable(true);
    rightPane.setName("rightPane");

    // Center + Right
    JSplitPane centerPlusRightPane = new JSplitPane(HORIZONTAL_SPLIT, centerPane, rightPane);
    centerPlusRightPane.setBorder(null);
    centerPlusRightPane.setOneTouchExpandable(true);
    centerPlusRightPane.setName("centerPlusRightPane");

    // Global
    JSplitPane mainPane = new JSplitPane(HORIZONTAL_SPLIT, shapeSelector, centerPlusRightPane);
    mainPane.setBorder(null);
    mainPane.setOneTouchExpandable(true);
    mainPane.setResizeWeight(0d); // Give all free space to center+right part
    mainPane.setName("mainPane");

    frame.add(mainPane);

    // Menu bar
    frame.setJMenuBar(buildMenuBar());

    // Resource injection
    ResourceMap resource = OmrGui.getApplication().getContext().getResourceMap(getClass());
    resource.injectComponents(frame);

    // Wiring
    boardsPane.connect();

    // Initialize sheet selector with all repository sheet names
    sheetSelector.stateChanged(null);

    return frame;
}
 
Example 19
Source Project: hack-a-drone   File: VideoFrame.java    License: Apache License 2.0 4 votes vote down vote up
public VideoFrame() {
    frame = new JFrame("Video Frame");
    frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
    label = new JLabel();
    frame.add(label);
}
 
Example 20
public Test6325652(JFrame frame) {
    JDesktopPane desktop = new JDesktopPane();
    desktop.add(create(0));
    desktop.add(this.internal = create(1));
    frame.add(desktop);
}