There were multiple problems in that code, which indicate to me that you are attempting 'programming by magic'. That just won't work. You need to hit the tutorials and read the JavaDocs in order to have any chance of making a working GUI. This code compiles, runs and displays the tool-bar, but it is still far from ideal.
import javax.swing.*;
import java.awt.*;
public class FrmMainMenu {
public static void main(String main[]){
//Create Frame
JFrame frmMainMenu = new JFrame();
//Size Frame
frmMainMenu.setExtendedState(JFrame.MAXIMIZED_BOTH);
//Add Components
comLeftToolBar obj1 = new comLeftToolBar();
obj1.comCreateNavBar();
frmMainMenu.add(obj1);
frmMainMenu.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
//Display Frame
frmMainMenu.setVisible(true);
}
}
class comLeftToolBar extends JPanel{
//Create ToolBar
public void comCreateNavBar() {
setLayout(new BorderLayout());
JToolBar comNavToolBar = new JToolBar();
comNavButtons(comNavToolBar);
add(comNavToolBar, BorderLayout.PAGE_START);
}
//Create Buttons
public void comNavButtons(JToolBar comNavToolBar) {
JButton comNavButton = new JButton("Nav");
JButton comProButton = new JButton("Pro");
comNavToolBar.add(comNavButton);
comNavToolBar.add(comProButton);
}
//Create Navigation Bar
public void comLeftNavBar() {
JPanel comNavBar = new JPanel();
comNavBar.add(new comLeftToolBar());
}
}
Other tips
- Swing GUIs should be created and altered on the EDT (Event Dispatch Thread). See Concurrency in Swing for more details.
- Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or combinations of them, along with layout padding & borders for white space.