Hi all, im relatively new to Java programming and im having some problems with Swing. I am messing around with creating tables and placing them into a container at Center position using BorderLayout manager. However nothing is showing up when i compile and run the project. i am using netBeans.
I have been able to place other components at other positions within the JFrame i have created. If anybody could help as to why my table isnt showing id be chuffed. Ive include code for my class which extands JFrame, DMMain, the class below it, TableCreator, extends JTable and creates the table as you may have guessed. The project is ran from a class Main which does nothing except create and initialize an instance of DMMain.
// DMMain Class included below
public class DMMain extends JFrame
// Instance Variables
JFMain = new JFrame();
cp = getContentPane();
private void initComponents()
menu = new JMenuBar();
fileMenu = new JMenu("File");
helpMenu = new JMenu("Help");
fileOpen = new JMenuItem("Open");
fileExit = new JMenuItem("Exit");
helpHelp = new JMenuItem("Help");
helpAbout = new JMenuItem("About");
tc = new TableCreator();
You have a TableCreator class that extends JTable, but then inside your class you create another JTable. That is the issue here. You are adding the data to that variable table, but then you are adding the table creator to your frame. Rather than TableCreator extending a table, you may want to add a create() method that returns the created JTable. Then, you can add that table to the frame. In this case though, I'm not sure having a TableCreator class is really necessary since the data it is creating is hard coded anyway.