aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Removing a contentPane- HELP! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Removing a contentPane- HELP!" Watch "Removing a contentPane- HELP!" New topic
Author

Removing a contentPane- HELP!

Naf Rash
Ranch Hand

Joined: Feb 19, 2004
Posts: 85
How can I remove a contentPane and its contents (as a whole) so that another can be placed in that same space/area?
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580

D.
Naf Rash
Ranch Hand

Joined: Feb 19, 2004
Posts: 85
Sorry about this but what does myFrame in the code extract you provided refer to?
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
The JFrame whoose content pane you wish to remove/replace.
Naf Rash
Ranch Hand

Joined: Feb 19, 2004
Posts: 85
I can't believe this I'm still having problems. I've tried doing that but now I can't get passed the first contentPane. I have no idea of how i'm going to resolve this. I'll forward you my code and maybe you could have a look at it?
Also my menu bar is not coming up along with the tite for the dialogue box. PLEASE HELP!

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
public class connectionBox extends JFrame {
private JTextField url, uid;
private JPasswordField password;
private JLabel urllabel, uidlabel, passwordlabel;
private connectionBox cb;
private JButton mine;
Connection connection;
JFrame mainFrame;
public connectionBox(){
super ("Establishing a connection");
JMenuBar bar = new JMenuBar();//creates the menu bar
setJMenuBar(bar);//sets the menu-bar for the Frame
//create File Menu and Exit Menu
JMenu fileMenu = new JMenu ("File");
fileMenu.setMnemonic('F');
final JMenuItem startMining = new JMenuItem ("Start Mining");
startMining.setMnemonic('N');
startMining.addActionListener(
new ActionListener(){
public void actionPerformed (ActionEvent e){
if (e.getSource() == startMining)

connectionForm();

}
}
);
fileMenu.add(startMining);
JMenuItem exit = new JMenuItem ("Exit");
exit.setMnemonic ('X');
exit.addActionListener(
new ActionListener(){
public void actionPerformed (ActionEvent e){
System.exit(0);
}
}
);
fileMenu.add(exit);
bar.add(fileMenu); //add the File menu

//create the Help menu
JMenu helpMenu = new JMenu ("Help");
helpMenu.setMnemonic ('h');
JMenuItem startHelp = new JMenuItem ("Start Help");
startHelp.setMnemonic('s');
startHelp.addActionListener(
new ActionListener(){
public void actionPerformed (ActionEvent e){
// if this happens then implement the documentation

}
}
);

helpMenu.add(startHelp);
bar.add(helpMenu); //add the File menu


/* The following code is for the buttons that user sees, allowing the user to utilise the data
* mining tool without having to go through the menus avaialable, ie, having to go through the
* file menu. */
JFrame mainFrame = new JFrame();
//final Container contentPane = getContentPane();
JPanel panel = new JPanel();
final JButton startButton = new JButton ("Start");
final JButton exitButton = new JButton ("Exit");

startButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
if (e.getSource() == startButton){
connectionForm();

}

}
}
);

exitButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
);
panel.add(startButton,"South");
panel.add (exitButton, "South");
mainFrame.setContentPane(bar);
mainFrame.setContentPane(panel);
mainFrame.setSize(500,200);
mainFrame.show();




}
public static void main(String args[]){
connectionBox app = new connectionBox();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing (WindowEvent e){
System.exit(0);
}
}
);
}
//inner class for event handling
private void connectionForm(){


JPanel all = new JPanel();
/* The following code provides a text box and asks for the URL of the database that needs to be
* connected to.*/
JPanel northPanel = new JPanel();
urllabel = new JLabel (" Enter the name of the database.");
northPanel.add(urllabel,BorderLayout.NORTH);
all.add(northPanel,BorderLayout.NORTH);
url = new JTextField (15);
all.add(url,BorderLayout.NORTH);
/* The following code provides a text box and asks for the User-ID to allow a connection to the
* database to be established. */
JPanel centrePanel = new JPanel();
uidlabel = new JLabel (" Enter the User-ID for the specified database."
+ "NB: If no User-ID exists enter 'null'.");
centrePanel.add(uidlabel);
all.add(centrePanel,BorderLayout.CENTER);
uid = new JTextField (15);all.add(uid,BorderLayout.CENTER);
/* The following code provides a text box and asks for the Password to allow a connection to the
* database to be established. */
JPanel southPanel = new JPanel();
passwordlabel = new JLabel (" Enter the Password for the specified" +
"database. NB: If no Password exists enter 'null'.");
southPanel.add(passwordlabel);
all.add(southPanel, BorderLayout.CENTER);
password = new JPasswordField (15);
all.add(password, BorderLayout.CENTER);
JPanel minePanel= new JPanel();
mine = new JButton("Mine!");
minePanel.add(mine, BorderLayout.SOUTH);
all.add(minePanel, BorderLayout.SOUTH);
ActionHandler handler = new ActionHandler();
url.addActionListener(handler); uid.addActionListener(handler);
password.addActionListener(handler);
mine.addActionListener(handler);
mainFrame.setContentPane(all);
mainFrame.validate();
mainFrame.setSize (600, 300);
mainFrame.show();

}
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
In your example your connectionBox instance *is* the JFrame (connectionBox extends JFrame).
I've made a few changes to your code to get you going :

D.
Naf Rash
Ranch Hand

Joined: Feb 19, 2004
Posts: 85
Thanks D - You really helped today!! I was in such a state trying to figure this out- been working on this all day. Its nice to have people like you when there are so many like me that just can't deal with Java! Thank you so much.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Glad it helped. Time for a
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Removing a contentPane- HELP!