This isn't part of a game, but could someone help me out with this?

I’m having trouble with Swing lately and it doesn’t always want to display my components. One time it will, and the next… bupkis.
Here’s the code:
the Body.class

package com.amx.main;

import java.awt.Container;

import javax.swing.JFrame;

public class Body {
	public static Body frame;
	public JFrame window;
	private Container container;
	public FormBase form;
	
	public static void main(String[] args){
		frame = new Body();
	}
	public Body(){
		container = new Container();
		window = new JFrame("AMX Registry");
		window.setSize(1000, 600);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.setLocationRelativeTo(null);
		window.setResizable(false);
		window.setContentPane(container);
		window.setVisible(true);
		window.requestFocus();
		init();
	}
	private void init(){
		load68();
	}
	protected void load68(){
		new FormBase(this);
		System.out.println("Form loaded");
	}
	protected void load69(){
		
	}
	protected void load70(){
		
	}
	protected Container getContent(){
		return window.getContentPane();
	}
}

and the FormBase.class

package com.amx.main;

import javax.swing.*;

public class FormBase {
	private Body body;
	protected JTextArea VIN;
	protected JButton test;
	public FormBase(Body b){
		test = new JButton("TEST");
		VIN = new JTextArea("VIN NUMBER");
		this.body = b;
		addComponent(test,10,10,60,60);
		addComponent(VIN,10,80,300,20);
		
	}
	public void addComponent(JComponent c, int x,int y,int w,int h){
		c.setLocation(x, y);
		c.setSize(w, h);
		body.getContent().add(c);
	}
}

Do the System.out.println messages all print, and you still see nothing?

I don’t know if this will help, but I’ve had better success with the setBounds method than setSize, when dealing with components on a JFrame. For the JFrame itself, I do use setSize, as you do.

Then again, I don’t use JFrame as you do, in terms of dealing with the ContentPane and all. I find it simpler to have a JPanel in the JFrame, set to the same size (less border areas). It is pretty straightforward to add components to a JPanel. Perhaps there are additional benefits you are getting that I am unaware of. I’m not exactly a Swing whiz.

The messages print, and the window comes up, however, there are no buttons or text boxes.

You’re manipulating components outside the EDT, so anything could happen. Also, you’re not assigning your FormBase instance to anything – I suspect you meant to assign it to the “form” field you have in Body.

Yeah the formbase is kinda not used there.

yeah, i changed it so that the “form” field in the body class was equal to the new FormBase, but it still doesn’t work.

Bumping because the problem is still not rectified.

I’m not used to swing, but this is so strange…

The components appear if:
-you set window.setResizable to true and resize the window
-minimize the window and restore it
-mouse over the components location

EDIT: oh, i get it now. After you add the components, you got to call the repaint() method manually:

   protected void load68(){
      new FormBase(this);
      window.repaint();
      System.out.println("Form loaded");
   }

I added what you just said, but its still not working.

When you add or remove components, you need to call revalidate(), not just repaint()

And again, you ought to be doing it on the EDT. You can usually get away with going off the EDT before any UI is visible, but once it is, all bets are off.

Huzzah! adding revalidate() worked. As for EDT, I’m still rather new to this have honestly don’t have a clue what that is.

The EDT is the Event Dispatch Thread, and anything that works directly with the UI has to run on the EDT. Sometimes you can get away with not using it, but then it’s always a gamble.

Start with http://docs.oracle.com/javase/tutorial/uiswing/start/index.html and pay close attention to the way it uses SwingUtilities.invokeLater – that’s how you get things to run on the EDT from outside it.