Hi
I'm having a problem with adding an object derived from a JPanel to a container and having it display correctly.
The relevant pieces of the code are as follows;
...
public class TraceTool extends JFrame implements ActionListener{
...
private Container content;
private ContentPane panel; // a class which extends JPanel and is serializable.
...
public TraceTool() {
...
content = getContentPane();
panel = new ContentPane();
content.add(panel, BorderLayout.CENTER);
...
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == fileNew) {
fileDialog.setMode(FileDialog.SAVE);
fileDialog.setTitle("New"
fileDialog.show();
newFile = fileDialog.getFile();
directory = fileDialog.getDirectory();
window.setTitle(appTitle + " - " + newFile);
IOServices.newFile(requirementList, newFile, directory, panel); // serializes ContentPane object.
}
else if (source == fileOpen) {
fileDialog.setMode(FileDialog.LOAD);
fileDialog.setTitle("Open"
fileDialog.show();
newFile = fileDialog.getFile();
directory = fileDialog.getDirectory();
window.setTitle(appTitle + " - " + newFile);
content.remove(panel); // this appears to work
panel = IOServices.openFile(requirementList, newFile, directory); // deserializes ContentPane object.
content.add(panel, BorderLayout.CENTER); // doesn't update display.
...
I have tried adding a JButton to panel before serialization to see if it is displayed after it is deserialized and added to the container (content). I've tested that the serialization is working properly by checking the number of components contained within panel by calling the getComponentCount() method on the deserialized object. Adding one JButton returns 1 etc. although the JButton doesn't appear. Having added components displaying correctly only seems to work if it is done within the constructor.
I've been scratching my head over this for some time and would be grateful for any help. I have the feeling I'm missing something very obvious.
Thanks
I'm having a problem with adding an object derived from a JPanel to a container and having it display correctly.
The relevant pieces of the code are as follows;
...
public class TraceTool extends JFrame implements ActionListener{
...
private Container content;
private ContentPane panel; // a class which extends JPanel and is serializable.
...
public TraceTool() {
...
content = getContentPane();
panel = new ContentPane();
content.add(panel, BorderLayout.CENTER);
...
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == fileNew) {
fileDialog.setMode(FileDialog.SAVE);
fileDialog.setTitle("New"
fileDialog.show();
newFile = fileDialog.getFile();
directory = fileDialog.getDirectory();
window.setTitle(appTitle + " - " + newFile);
IOServices.newFile(requirementList, newFile, directory, panel); // serializes ContentPane object.
}
else if (source == fileOpen) {
fileDialog.setMode(FileDialog.LOAD);
fileDialog.setTitle("Open"
fileDialog.show();
newFile = fileDialog.getFile();
directory = fileDialog.getDirectory();
window.setTitle(appTitle + " - " + newFile);
content.remove(panel); // this appears to work
panel = IOServices.openFile(requirementList, newFile, directory); // deserializes ContentPane object.
content.add(panel, BorderLayout.CENTER); // doesn't update display.
...
I have tried adding a JButton to panel before serialization to see if it is displayed after it is deserialized and added to the container (content). I've tested that the serialization is working properly by checking the number of components contained within panel by calling the getComponentCount() method on the deserialized object. Adding one JButton returns 1 etc. although the JButton doesn't appear. Having added components displaying correctly only seems to work if it is done within the constructor.
I've been scratching my head over this for some time and would be grateful for any help. I have the feeling I'm missing something very obvious.
Thanks