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

The following are Jave code examples for showing how to use add() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: MissingDragExitEventTest.java   View Source Code Vote up 6 votes
private static void initAndShowUI() {
    frame = new JFrame("Test frame");

    frame.setSize(SIZE, SIZE);
    frame.setLocationRelativeTo(null);
    final JTextArea jta = new JTextArea();
    jta.setBackground(Color.RED);
    frame.add(jta);
    jta.setText("1234567890");
    jta.setFont(jta.getFont().deriveFont(150f));
    jta.setDragEnabled(true);
    jta.selectAll();
    jta.setDropTarget(new DropTarget(jta, DnDConstants.ACTION_COPY,
                                     new TestdropTargetListener()));
    jta.addMouseListener(new TestMouseAdapter());
    frame.setVisible(true);
}
 
Example 2
Project: openjdk-jdk10   File: Test7163696.java   View Source Code Vote up 6 votes
public void run() {
    if (this.bar == null) {
        this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100);
        this.bar.setPreferredSize(new Dimension(400, 20));

        JFrame frame = new JFrame();
        frame.add(this.bar);
        frame.pack();
        frame.setVisible(true);
    }
    else if (40 != this.bar.getValue()) {
        System.out.println("name = " + UIManager.getLookAndFeel().getName());
        System.out.println("value = " + this.bar.getValue());
    }
    else {
        SwingUtilities.getWindowAncestor(this.bar).dispose();
        this.bar = null;
    }
}
 
Example 3
Project: openjdk-jdk10   File: HiddenDefaultButtonTest.java   View Source Code Vote up 6 votes
private static void createGUI() {
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton button = new JButton("Default button");
    button.setDefaultCapable(true);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ButtonClickCount++;
        }
    });

    frame.add(button);
    button.setVisible(false);

    frame.getRootPane().setDefaultButton(button);

    frame.setSize(200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 4
Project: openjdk-jdk10   File: JInternalFrameDraggingTest.java   View Source Code Vote up 6 votes
private static void createAndShowGUI() {

        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new BorderLayout());

        desktopPane = new JDesktopPane();
        desktopPane.setBackground(BACKGROUND_COLOR);

        frame.add(desktopPane, BorderLayout.CENTER);
        frame.setSize(FRAME_SIZE, FRAME_SIZE);
        frame.setVisible(true);

        internalFrame = new JInternalFrame("Test");
        internalFrame.setSize(FRAME_SIZE / 2, FRAME_SIZE / 2);
        desktopPane.add(internalFrame);
        internalFrame.setVisible(true);
        internalFrame.setResizable(true);

        frame.setVisible(true);
    }
 
Example 5
Project: slick   File: Example_AppLayout.java   View Source Code Vote up 6 votes
public static void main(String[] args) 
{
	JPanel header = new ColorPanel( Color.decode("#C6C6C6"), new Dimension(900, 64) ); 
	JPanel navbar = new ColorPanel( Color.decode("#444444"), new Dimension(200, 550) );
	JPanel contentPanel = new ColorPanel( Color.decode("#EEEEEE"), new Dimension(700, 550) );

	JFrame frame = new JFrame("Example App Layout");
	frame.setLayout( new SlickLayout() ); 
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

	//first row
	frame.add( header, new SlickConstraint(0, SlickConstraint.HorizontalFill, SlickConstraint.VerticalPack) );

	//second row
	frame.add( navbar, new SlickConstraint(1, SlickConstraint.HorizontalPack, SlickConstraint.VerticalFill) );
	frame.add( contentPanel, new SlickConstraint(1, SlickConstraint.HorizontalFill, SlickConstraint.VerticalFill) );

	frame.pack();
	frame.setVisible(true);
}
 
Example 6
Project: openjdk-jdk10   File: JComboBoxOverlapping.java   View Source Code Vote up 6 votes
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 7
Project: SWEngProject   File: Menu.java   View Source Code Vote up 6 votes
private void resetLoginUI(int x, int y, JFrame f, JPanel loginPanel, JLabel logoLabel,
		JTextField usernameTextField, JTextField passwordTextField,
		JButton signInButton, JButton logInButton, JButton settingsButton,
		JLabel bgLabel) {

	int i = y - 520;

	f.remove(loginPanel);
	f.setSize(x, y);
	f.revalidate();

	loginPanel.setBounds(0, 0, x, y);
	logoLabel.setBounds(x / 2 - 200, i / 2, 400, 190);
	usernameTextField.setBounds(x / 2 - 200, i / 2 + 200, 400, 100);
	passwordTextField.setBounds(x / 2 - 200, i / 2 + 310, 400, 100);
	signInButton.setBounds(x / 2 - 200, i / 2 + 420, 195, 100);
	logInButton.setBounds(x / 2 + 5, i / 2 + 420, 195, 100);
	settingsButton.setBounds(x - 70, 10, 60, 60);
	bgLabel.setBounds(0, 0, x, y);

	f.add(loginPanel);
	f.revalidate();
	f.repaint();

}
 
Example 8
Project: POC-Ray-Tracer   File: RTracerDemo.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws InterruptedException {
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		NaiveRayTracer world = createWorld();
		RayTracerPanel panel = new RayTracerPanel(world, 600,600);
		
		frame.add(panel);
		frame.pack();
		
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		
//		while(true) {
//			Thread.sleep(16);
//			panel.doRenderToBuffer();
//		}
	}
 
Example 9
Project: openjdk-jdk10   File: MouseModifiersInKeyEvent.java   View Source Code Vote up 5 votes
private static void createAndShowGUI() {
    f = new JFrame();

    final Component component = new JTextField();
    component.addKeyListener(new MyKeyListener());

    f.add(component);
    f.setSize(300, 300);
    f.setLocationRelativeTo(null);
    f.setAlwaysOnTop(true);
    f.setVisible(true);
}
 
Example 10
Project: VASSAL-src   File: StringEnumConfigurer.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
  JFrame f = new JFrame();
  StringEnumConfigurer c = new StringEnumConfigurer(null, "Pick one: ", new String[]{"one", "two", "three"}); //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
  c.addPropertyChangeListener(new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent evt) {
      System.err.println(evt.getPropertyName() + " = " + evt.getNewValue()); //$NON-NLS-1$
    }
  });
  f.add(c.getControls());
  f.pack();
  f.setVisible(true);
}
 
Example 11
Project: LivroJavaComoProgramar10Edicao   File: LabelDemo.java   View Source Code Vote up 5 votes
public static void main(String[] args)
{
   // Create a label with plain text
   JLabel northLabel = new JLabel("North");
   
   // create an icon from an image so we can put it on a JLabel
   ImageIcon labelIcon = new ImageIcon("GUItip.gif");
   
   // create a label with an Icon instead of text
   JLabel centerLabel = new JLabel(labelIcon);
   
   // create another label with an Icon
   JLabel southLabel = new JLabel(labelIcon);
   
   // set the label to display text (as well as an icon)
   southLabel.setText("South");
   
    // create a frame to hold the labels
   JFrame application = new JFrame();
   
   application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   // add the labels to the frame; the second argument specifies
   // where on the frame to add the label 
   application.add(northLabel, BorderLayout.NORTH);
   application.add(centerLabel, BorderLayout.CENTER);      
   application.add(southLabel, BorderLayout.SOUTH);      

   application.setSize(300, 300); // set the size of the frame
   application.setVisible(true); // show the frame
}
 
Example 12
Project: Install_Builder_Universal   File: AboutWindow.java   View Source Code Vote up 5 votes
public AboutWindow() {
	frame = new JFrame();
	frame.setTitle("About");
	frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	frame.setSize(325, 280);
	frame.setLocationRelativeTo(null);
	frame.setResizable(false);
	frame.setLayout(null);
	
	panel = new JPanel();
	frame.add(panel);
	
	initialize();
	frame.setVisible(true);
}
 
Example 13
Project: LivroJavaComoProgramar10Edicao   File: TestDraw.java   View Source Code Vote up 5 votes
public static void main(String[] args)
{
   DrawPanel panel = new DrawPanel();      
   JFrame app = new JFrame();
   
   app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   app.add(panel);
   app.setSize(300, 300);
   app.setVisible(true);
}
 
Example 14
Project: openjdk-jdk10   File: bug8069348.java   View Source Code Vote up 5 votes
private static void createAndShowGUI() {

        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JDesktopPane desktopPane = new JDesktopPane();
        desktopPane.setBackground(DESKTOPPANE_COLOR);

        internalFrame = new JInternalFrame("Test") {

            @Override
            public void paint(Graphics g) {
                super.paint(g);
                g.setColor(FRAME_COLOR);
                g.fillRect(0, 0, getWidth(), getHeight());
            }
        };
        internalFrame.setSize(WIN_WIDTH / 3, WIN_HEIGHT / 3);
        internalFrame.setVisible(true);
        desktopPane.add(internalFrame);

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(desktopPane, BorderLayout.CENTER);
        frame.add(panel);
        frame.setSize(WIN_WIDTH, WIN_HEIGHT);
        frame.setVisible(true);
        frame.requestFocus();
    }
 
Example 15
Project: Tarski   File: Visualization.java   View Source Code Vote up 5 votes
public void showMetamodel() {
  xmlCreator.setMetamodel(true);
  frame = new JFrame("Visualization");
  frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  frame.add(getGraph(), BorderLayout.CENTER);
  frame.setVisible(true);
  frame.setSize(500, 500);
}
 
Example 16
Project: jdk8u-jdk   File: Test6199676.java   View Source Code Vote up 5 votes
public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();

        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    }
    else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    }
    else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    }
    catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
 
Example 17
Project: openjdk-jdk10   File: Test6325652.java   View Source Code Vote up 4 votes
public Test6325652(JFrame frame) {
    JDesktopPane desktop = new JDesktopPane();
    desktop.add(create(0));
    desktop.add(this.internal = create(1));
    frame.add(desktop);
}
 
Example 18
Project: Wilmersdorf_SER316   File: AppFrame.java   View Source Code Vote up 4 votes
public void configureSMSFunctionality()
  {
  	System.out.println("configurateSMSFunctionality called");
  	JPanel topSMSPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  	JPanel centerSMSPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  	JPanel bottomSMSPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  	
  	SMSGui = new JFrame();
SMSGui.setSize(450, 200);
SMSGui.setLayout(new FlowLayout(FlowLayout.LEFT));
SMSGui.setTitle("Configure SMS Reminders");
SMSGui.setLocationRelativeTo(null);

   JLabel spacer = new JLabel("       ");//spacer
  	JLabel phoneNumberPrompt = new JLabel("Phone Number:");
  	JLabel carrierPrompt = new JLabel("Select Carrier:");
  	JLabel passwordPrompt = new JLabel("Password:");
  	passwordField = new JTextField(10);
  	passwordField.setToolTipText("Password is Memoranda");
  	phoneNumberField = new JTextField(10);
  	carrierList = new JComboBox<String>();
  	carrierList.addItem("T-Mobile");//@tmomail.net 
  	carrierList.addItem("Sprint");//@messaging.sprintpcs.com
  	carrierList.addItem("Verizon");//@vtext.com
  	carrierList.addItem("Virgin");//@vmobl.com
  	carrierList.addItem("Cingular");//@cingularme.com
  	carrierList.addItem("Nextel");//@messaging.nextel.com
  	
      JButton setConfigurationButton = new JButton("Set Configuration");
      setConfigurationButton.addActionListener(captureSMSConfiguration);
      
      topSMSPanel.add(phoneNumberPrompt);
      topSMSPanel.add(phoneNumberField);
      
      centerSMSPanel.add(carrierPrompt);
      centerSMSPanel.add(carrierList);
      
      bottomSMSPanel.add(passwordPrompt);
      bottomSMSPanel.add(passwordField);
      bottomSMSPanel.add(spacer);
      bottomSMSPanel.add(setConfigurationButton);
      
      SMSGui.add(topSMSPanel);
      SMSGui.add(centerSMSPanel);
      SMSGui.add(bottomSMSPanel);
      
      SMSGui.setVisible(true);
  }
 
Example 19
Project: Mafia   File: Window.java   View Source Code Vote up 4 votes
public Window(int width, int height, String title, boolean resizable) {
	frame = new JFrame();
	game = new Game();
	
	
	frame.setMinimumSize(new Dimension(width, height));
	frame.setSize(width, height);
	
	frame.setTitle(title);
	frame.setResizable(resizable);
	
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	
	frame.add(game);
	
	frame.setLocationRelativeTo(null);
}
 
Example 20
Project: JFrame   File: Source.java   View Source Code Vote up 4 votes
public void gui(){

	frame = new JFrame("Begin");
	frame.setVisible(true);
	frame.setSize(700, 500);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	panel = new JPanel();
	panel.setBackground(Color.GREEN);
	
	button = new JButton("Click");
	label = new JLabel("Label");
	
	
	panel.add(button);
	panel.add(label);
	
	frame.add(panel); //add panel to frame
	
}