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);
}
}