-1

My application runs fine on eclipse IDE, but after exporting it, the fame won't repaint. i am trying to rebuild the lay out of JFrame by removing two JPanels and add them again with more panels & here is my code:

the app first calls buildGUI()

 private void buildGUI(){
        setTitle("MyApp");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setContentPane(new BackGroundImagePanel());
        setResizable(false);
        getContentPane().setLayout(new GridBagLayout());
        c = new GridBagConstraints();

        /*
        *set up GridBagConstraints and add the two panels
        */

        pack();
        setSize(700, 700);
        revalidate();
        setLocationRelativeTo(null);
    }

Upon user input do some calculations & call reBuildGUI():

private void reBuildGUI(){
        //Clean the frame.
        remove(firstPanel);
        remove(secondPanel);
        //removeAll() doesn't work for me;
        validate();
        repaint();

        /*
        *set up GridBagConstraints and more panels
        */

        pack();
        setSize(700, 700);
        repaint();
        validate();
}

again, the application work perfict on the IDE but not as stand alone jar, upon calling reBuildGUI() nothing happen ! Tried to use validate(), revalidate() & pack() in different orders with no gain ?

  • 3
    Not sure how anyone can answer this without your posting a [mcve] other than to make sure that you get all images as class resources and not as files. If you still need help, then work on isolating the bug, and post your MCVE. – Hovercraft Full Of Eels Aug 04 '16 at 21:34
  • 1
    Don't use `setSize()` *and* `pack()`, use `setSize()` if you want the `JFrame` to be a specific size *or* use `pack()` if you want the `JFrame` to be the smallest size possible to fit its child components. – MasterBlaster Aug 04 '16 at 21:37

1 Answers1

0

Hovercraft: you was right the code is not enough, sorry but i would paste pages of code and wouldn't be enough to debug this.

here is the troubleshooting: - directing the logger to log into file (using file handler) . - found where the logger stop. - added finer & finest log records till find the bug.

the error was burried far deep inside another class method in this line:

addOnImage = ImageIO.read(getClass().getClassLoader().getResource("images/AddTextOn.png"));

the actual file name was "ADDTextOn.png" but Eclipse was able to read it as "AddTextOn.png" while the JRE wasn't, but nothing was happening to indicate any errors, the program was just do nothing.