• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

Refresh Panel inside JFrame Not working!

I have JFrame which contains a Panel and inside that panel i have a splitpane. At first i load the Panel into the JFrame :
// JFrame constructor
 public Donnees(){
        super("Regression:Menu Principal");
        setC(getContentPane());
        // create Object Panel which extends JPanel
        PanelPrincipale panel = new PanelPrincipale();
     // insert 2 enpty JPanel objects in it
        panel.update(null,null);
       
        getC().add(panel);
        initialization();
        setSize( 700, 500 );
        setLocation(200,200);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        setVisible(true);
    }

// Class PanelPrincipale
public PanelPrincipale() {
        super();
       
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    }
    // Method which splits the screen
    public void update(JPanel panel1, JPanel panel2){
       
        JScrollPane demoScrollPane = new JScrollPane(panel1);
        JScrollPane tabScrollPane = new JScrollPane(panel2);
        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
                demoScrollPane, tabScrollPane);
        splitPane.setOneTouchExpandable(true);
        splitPane.setDividerLocation(250);
       
        Dimension minimumSize = new Dimension(100, 50);
        splitPane.setPreferredSize(new Dimension(690, 500));
        add(splitPane);
       
    }


// in here i will create 2 panels data and nature and send them to the method Update(data,nature)
But the screen is not refreshing why?
public void showTable(){
        ChargementDonnees cd = new ChargementDonnees(getFile());
        Data data = new Data(cd);
        ChargementNature cn = new ChargementNature();
        Nature nature = new Nature(cn);
         MenuTabs tabs = new MenuTabs();
        tabs.ajoutTab(nature,"nature");
        PanelPrincipale panel = new PanelPrincipale();
        panel.update(data,nature);
        panel.invalidate();
        panel.validate();
   }  
0
dadadude
Asked:
dadadude
2 Solutions
 
objectsCommented:
you don't appear to add 'panel' to your gui (and call revalidate on the container u add it 2)

0
 
dadadudeAuthor Commented:
public Donnees(){
        super("Regression:Menu Principal");
        setC(getContentPane());
        // create Object Panel which extends JPanel
        PanelPrincipale panel = new PanelPrincipale();
     // insert 2 enpty JPanel objects in it
        panel.update(null,null);
here it is i added the panel
0
 
dadadudeAuthor Commented:
getC().add(panel);
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
objectsCommented:
yes u add that panel there, but you create a new panel in showTable() that does not get added.
0
 
dadadudeAuthor Commented:
public class SplitEcran extends PanelPrincipale{

    private File file;
   
   
    /**
     * Constructeur
     */
    public SplitEcran(File _file) {
        super();
        this.setFile(_file);
        showTable();
    }

    public void showTable(){
        ChargementDonnees cd = new ChargementDonnees(getFile());
        Data data = new Data(cd);
        ChargementNature cn = new ChargementNature();
        Nature nature = new Nature(cn);
         MenuTabs tabs = new MenuTabs();
        tabs.ajoutTab(nature,"nature");
        update(data,nature);
       
   }  

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }
}

i made the class that has the method showtable extends PagePrincipale JPanel :( What should i do then?
Please help me!
How should i solve the problem. do you have a solution?
0
 
CEHJCommented:
>>
// insert 2 enpty JPanel objects in it
        panel.update(null,null);
>>

But you're not doing what your  comment says. That should be

// insert 2 enpty JPanel objects in it
        panel.update(new JPanel(), new JPanel());
0
 
objectsCommented:
depends whhether you want to add a new panel (in which case add the newly created panel as I described above), or if you want to replace the existing one then make panbel a member variable and replace it

        PanelPrincipale panel = new PanelPrincipale();

 public Donnees(){
        super("Regression:Menu Principal");
        setC(getContentPane());
        // create Object Panel which extends JPanel
     // insert 2 enpty JPanel objects in it
        panel.update(null,null);
       
        getC().add(panel);
        initialization();
        setSize( 700, 500 );
        setLocation(200,200);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        setVisible(true);
    }

public void showTable(){
        ChargementDonnees cd = new ChargementDonnees(getFile());
        Data data = new Data(cd);
        ChargementNature cn = new ChargementNature();
        Nature nature = new Nature(cn);
         MenuTabs tabs = new MenuTabs();
        tabs.ajoutTab(nature,"nature");

        // remove existing panel
         remove(panel);

         // add new one

        panel = new PanelPrincipale();
        panel.update(data,nature);
        revalidate();
   }  
0
 
objectsCommented:
If the showTable() method is in a different class then instead return the panel, and update your frame in calling class

public JPanel showTable(){
        ChargementDonnees cd = new ChargementDonnees(getFile());
        Data data = new Data(cd);
        ChargementNature cn = new ChargementNature();
        Nature nature = new Nature(cn);
         MenuTabs tabs = new MenuTabs();
        tabs.ajoutTab(nature,"nature");
        PanelPrincipale panel = new PanelPrincipale();
        panel.update(data,nature);
       return panel;
   }  
0
 
dadadudeAuthor Commented:
I will try this way. i will tell you later
0
 
objectsCommented:
missed adding it, above.  Add it before validating
   
        add(panel);
        revalidate();
0
 
dadadudeAuthor Commented:
i added this to the class SplitEcran or in english splitScreen:
public class SplitEcran {

    private File file;
    private PanelPrincipale panel;
   
   
    /**
     * Constructeur
     */
    public SplitEcran(File _file) {
        super();
        this.setFile(_file);
        showTable();
    }

    public void showTable(){
        ChargementDonnees cd = new ChargementDonnees(getFile());
        Data data = new Data(cd);
        ChargementNature cn = new ChargementNature();
        Nature nature = new Nature(cn);
         MenuTabs tabs = new MenuTabs();
        tabs.ajoutTab(nature,"nature");
       panel = new PanelPrincipale();
        panel.update(data,nature);  
   }  

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }
    // return an object of type PanelPrincipale
    public PanelPrincipale getPanel(){
        return panel;
    }
}

the proble is that i call show table from another class that handles all the actionlisteners
 f = jfc.getSelectedFile();
String extension = Extension.getExtension(f);
           
SplitEcran split = new SplitEcran(f);

// Class panelPrincipale
public class PanelPrincipale extends JPanel{
   
   
    /** Creates a new instance of PanelPrincipale */
   
    public PanelPrincipale() {
        super();
       
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
       
    }
   
    public void update(JPanel panel1, JPanel panel2){
       
        JScrollPane demoScrollPane = new JScrollPane(panel1);
        JScrollPane tabScrollPane = new JScrollPane(panel2);
        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
                demoScrollPane, tabScrollPane);
        splitPane.setOneTouchExpandable(true);
        splitPane.setDividerLocation(250);
       
        Dimension minimumSize = new Dimension(100, 50);
        splitPane.setPreferredSize(new Dimension(690, 500));
        add(splitPane);
       
    }
}

What should i do now? i have to create an object of the JFrame?
i tried this each time that i create it i opens a new window i will have 2 windows each time that i create it.
0
 
objectsCommented:
the class that calls showTable() needs to update the frame as required
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now