I cannot get the JFrame to display my JPanel. Either that, or my JPanel isn't displaying my JScrollPane.
Here's my code:
public class PokeBase extends JFrame
{
private static final long serialVersionUID = 1L;
private static final int WIDTH = 1280;
private static final int HEIGHT = 720;
public static void main(String[] args)
{
new PokeBase().setVisible(true);
}
public PokeBase()
{
super("PokeBase - Complete DataBase of Pokemon");
Pokemon.init();
initGUI();
}
private void initGUI()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setLocation(getX() - WIDTH / 2, getY() - HEIGHT / 2);
this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
this.setResizable(false);
addGUIComponents();
this.pack();
}
private void addGUIComponents()
{
JPanel menuPanel = new JPanel();
menuPanel.setLocation(0, 0);
menuPanel.setPreferredSize(new Dimension(200, HEIGHT));
menuPanel.setVisible(true);
JScrollPane treeView = new JScrollPane();
DefaultMutableTreeNode pokemonList = new DefaultMutableTreeNode("Pokemon");
DefaultMutableTreeNode bulb = new DefaultMutableTreeNode(Pokemon.bulbasaur.getName());
pokemonList.add(bulb);
JTree tree = new JTree(pokemonList);
menuPanel.add(treeView);
this.add(menuPanel);
}
}
I haven't worked with JScrollPane's before, or JTree's either.
Also, I had to do Some trickery because when I centered the form using setLocationRelativeTo(null);
, it centered using the top left corner. I don't remember this being a problem...