Okay, I basically have a menu bar with menuItems.. say just showTableMenuItem --> to display the table .... and addMenuItem() --> to add new record. I want to be able to display the table (when user clicks on the button), and then disappear the table and display the addMenu page(when user clicks the addMenu button). and then maybe display the table again and disappear the addMenu page depends on what the user clicks. (ideally do this with JPanel or JScrollerPane, i do'nt want floating JInternalFrame)

Apparently, simply set something visible to false and then set something else visible to true isn't the solution. (or maybe i had something else wrong causing this not working)

****************************************************
if anyone can explain the way to make one thing goes away and set another thing appear without conflict, this is all i need.

no need to debug this for me. Thanks.
****************************************************
//////// if you need some reference to see what the problem is///

public class Screen extends JFrame implements ActionListener
{
	private static DataHolder dh = new DataHolder();
	private static JMenuBar menuBar;
	private static JMenu menuFile;
	private static JMenu menuEdit; 
	private static JMenuItem openMenuItem, closeMenuItem, printMenuItem;
	private static JMenuItem showTableMenuItem, addMenuItem;
	private static JTable table; 
	private static JScrollPane tableScroller; 
	private static JPanel infoBoardPanel; // addScrollerPanel;
	private JInternalFrame addScrollerPanel;
	
	public Screen() throws SQLException
	{
		////////////// Menu Bar File items //////////////////
		openMenuItem = new JMenuItem("Open");
		openMenuItem.setHorizontalTextPosition(SwingConstants.LEFT);
		openMenuItem.setAccelerator(KeyStroke.getKeyStroke('o', java.awt.Event.CTRL_MASK, false));
		//openMenuItem.addActionListener(new ActionPerform(i));
		
		closeMenuItem = new JMenuItem("Close");
		closeMenuItem.setAccelerator(KeyStroke.getKeyStroke('q', java.awt.Event.CTRL_MASK, false));
		closeMenuItem.addActionListener(new closeMenuHandler());
		
		
		printMenuItem = new JMenuItem("Print");
		printMenuItem.setAccelerator(KeyStroke.getKeyStroke('p', java.awt.Event.CTRL_MASK, false));

		//////////// Menu Bar Edit items /////////////////
		showTableMenuItem = new JMenuItem("Show Table");
		showTableMenuItem.addActionListener(this);
		
		addMenuItem = new JMenuItem("Add Record");
		addMenuItem.addActionListener(this);
		//////////////////////////////////////////
		
		
		
		///////////////// menu /////////////////
		
		//////// file ////////
		menuFile = new JMenu("File");
		menuFile.add(openMenuItem);
		menuFile.addSeparator();
		menuFile.add(printMenuItem);
		menuFile.add(closeMenuItem);
		
		///////////////////////
		
		//////// edit ////////
		menuEdit= new JMenu("Edit");
		menuEdit.add(showTableMenuItem);
		menuEdit.add(addMenuItem);
		/////////////////////
		
		//////// menu bar /////////
		menuBar = new JMenuBar();
		menuBar.add(menuFile);
		menuBar.add(menuEdit);
		/////////////////////////
		
		
		
		
		
	    
	    ////// info board ///// 
	    JLabel msg = new JLabel("Welcome to Henry's Employee Database! Please click on \"edit\" on the menu bar for options", JLabel.CENTER);
	    infoBoardPanel = new JPanel();
	    infoBoardPanel.setBackground(java.awt.Color.GREEN);
	    infoBoardPanel.add(msg);
	   /////////////////////////
	    
	    
	    
		
	    
	
	    /////////////////  Frame setup (menu bar and message board) //////////////

		setTitle("Employee Record");
	    add(menuBar, BorderLayout.NORTH);  // add the menu bar
	    add(infoBoardPanel, BorderLayout.CENTER);
	   
	    
	    
	    addWindowListener(new WinClosing());
		setBounds(100, 100, 1000, 500);
		setVisible(true);
		
		////////////////////End Frame basic setup //////////////////////////////
		
	}// end screen constructor
	
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == showTableMenuItem)
		{
			infoBoardPanel.setVisible(false);
			
			        ////////////////table /////////////////
			try
			{
				table = new JTable(dh.getRowData(), dh.getColumnNames());
				table.setAutoCreateRowSorter(true);
				table.setBackground(java.awt.Color.lightGray);
			}
			catch(SQLException sqle)
			{
				sqle.printStackTrace();
			}
			
			///////////////////put table in the scroller and display /////////////////////
			tableScroller = new JScrollPane(table);
			add(tableScroller);		// add tableScroller to the Frame
			tableScroller.setVisible(true);
			
		}
		
		else if (e.getSource() == addMenuItem)
		{
			//tableScroller.setVisible(false);
			//remove(tableScroller);
			infoBoardPanel.setVisible(false);
			addScrollerPanel = new JInternalFrame();
		    //addScrollerPanel = new JPanel();
			addScrollerPanel.setLayout(new GridLayout(12, 2));
		    
		    
		    addScrollerPanel.add(new Label("ID#:"));
		    JTextField idField = new JTextField();
		    addScrollerPanel.add(idField);
		    addScrollerPanel.add(new Label("First Name:"));
		    JTextField fnField = new JTextField();
		    addScrollerPanel.add(fnField);
		    addScrollerPanel.add(new Label("Last Name:"));
		    JTextField lnField = new JTextField();
		    addScrollerPanel.add(lnField);
		    addScrollerPanel.add(new Label("Telephone:"));
		    JTextField phoneField = new JTextField();
		    addScrollerPanel.add(phoneField);
		    addScrollerPanel.add(new Label("Address:"));
		    JTextField addField = new JTextField();
		    addScrollerPanel.add(addField);
		    addScrollerPanel.add(new Label("City:"));
		    JTextField cityField = new JTextField();
		    addScrollerPanel.add(cityField);
		    addScrollerPanel.add(new Label("State:"));
		    JTextField stateField = new JTextField();
		    addScrollerPanel.add(stateField);
		    addScrollerPanel.add(new Label("Zip Code:"));
		    JTextField zipField = new JTextField();
		    addScrollerPanel.add(zipField);
		    addScrollerPanel.add(new Label("Sex:"));
		    JTextField sexField = new JTextField();
		    addScrollerPanel.add(sexField);
		    addScrollerPanel.add(new Label("Age:"));
		    JTextField ageField = new JTextField();
		    addScrollerPanel.add(ageField);
		    addScrollerPanel.add(new Label("Hourly Rate:"));
		    JTextField hourlyField = new JTextField();
		    addScrollerPanel.add(hourlyField);
		    addScrollerPanel.add(new Label("Hours per week:"));
		    JTextField hoursField = new JTextField();
		    addScrollerPanel.add(hoursField);
		    
		    add(addScrollerPanel, BorderLayout.CENTER);
			addScrollerPanel.setVisible(true);
		}
	}

Using setVisible(true) on the JFrame should be making it appear.

However, I noticed that you're removing a Container, the JScrollPane, from the JFrame after setting it to invisible. Why not just remove it, then call the validate method? http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Container.html#validate()

edit: I'm going to run your code and see if I can figure out what's going on. Nevermind, I'd need to know where some of your classes came from.

Example method

private void showPanel(JPanel panel){
        Container contentPane = getContentPane();
        contentPane.removeAll();
        contentPane.add(panel);
        pack();        
    }

Thank you all very very much. Ezzaral, i like your simple sample code. that just explained everything i needed to know. thank you very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.