Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

When adding a customized JPanel, everything disappears

Thread view: 
Justin - 30 Aug 2007 21:10 GMT
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);

   }

}
Justin - 30 Aug 2007 21:33 GMT
> 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.
[quoted text clipped - 93 lines]
>
> - Show quoted text -

Nevermind, been a couple months since I've written anything, and I
forgot the mysterious power of the validate() method.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.