Question

I have a form stored in both the inputWidget and the outputWidget. The buttons addInput and addOutput will show two different forms in the secondaryInOutPanel.

However there is a significant delay when moving between the form by clicking the buttons. In fact it changes when I attempting to click on the form. And there is still some visible drawings from the pervious form.

I tried using SwingUtilities but that caused the delay to be worst.

    secondaryInOutPanel = new JPanel(new BorderLayout());
    secondaryInOutPanel.setMinimumSize(new Dimension(200,400));     

    JPanel btnPanel = new JPanel();
    outinPanel.add(btnPanel, BorderLayout.NORTH);

    JButton addInput = new JButton("Add Input");
    btnPanel.add(addInput);
    addInput.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            secondaryInOutPanel.removeAll();                                
            secondaryInOutPanel.add(inputWidget, BorderLayout.NORTH);               
            JButton addBtn = new JButton("Save Input");
            secondaryInOutPanel.add(addBtn, BorderLayout.SOUTH);
            addBtn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub                      
                }                   
            });
        }
    });

    JButton addOutput = new JButton("Add Output");
    btnPanel.add(addOutput);
    addOutput.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            secondaryInOutPanel.removeAll();                            
            secondaryInOutPanel.add(outputWidget, BorderLayout.NORTH);              
            JButton addBtn = new JButton("Save Output");
            secondaryInOutPanel.add(addBtn, BorderLayout.SOUTH);
            addBtn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub                      
                }                   
            });
        }
    }); 
Was it helpful?

Solution

A better design is to use a Card Layout to hold your input and output panels. Then you can just swap panels as required. The CardLayout will then manage the revalidating and repainting of the panel for you.

OTHER TIPS

You need to make a call to revalidate() and or repaint() on the secondaryInOutPanel after you make changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top