When adding a customized JPanel, everything disappears
I am trying to write an application that uses a JSplitPane. I am
working on customizing the JPanel on the left side of the SplitPane.
So far, the only component I've added to the JPanel is a JScrollPane.
When I add the scrollpane, my splitPane nor my Menu appear when I run
the program. I've pasted my code below. If someone could explain to
me how to fix it, and more importantly, why it occurs, I would greatly
appreciate it. Thanks
CODE*********************************
****************************************
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import java.awt.Container;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
public class Main extends JFrame implements ActionListener{
private String database = "adsadf";
private DataConnection dc;
private LeftPanel leftPanel;
private JPanel rightPanel;
public Main() {
setVisible(true);
setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setExtendedState(JFrame.MAXIMIZED_BOTH);
leftPanel = new LeftPanel();
rightPanel = new JPanel();
JSplitPane splitPane = new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
splitPane.setSize(getSize());
splitPane.setDividerLocation(150);
Container c = getContentPane();
c.add(splitPane);
createMenuBar();
}
private void createMenuBar(){
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
menuBar.add(menu);
JMenuItem item = new JMenuItem("Exit");
item.setActionCommand("exit");
item.addActionListener(this);
menu.add(item);
setJMenuBar(menuBar);
}
public void actionPerformed(ActionEvent ae){
if(ae.getActionCommand().equals("exit")){
System.exit(0);
}
}
public static void main(String[] args) {
Main main = new Main();
}
}
//***************************************************
//******CUSTOM JPANEL***********************
//***************************************************
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class LeftPanel extends JPanel{
JScrollPane scroller;
public LeftPanel() {
super();
scroller = new JScrollPane();
add(scroller);
}
}