Hi, something weird happened with my program, I mean when I run it I see only grey frame (like I had only JFrame object in my app), then I minimalize application, maximalize it and only then I see all components painted (JButton, rectangels and lines inside Jpanel,...). Changing of frame size helped too, but now I have fixed size, so this is not anoption. Can you tell me what can cause that behaviour.

This is class which draw everything:

public class Simulation{
    JFrame frame;
    JPanel background;
    RoadSystem roads;
    Stats stats;
    Settings settings;
    JButton startButton;

    public Simulation() {
        frame = new JFrame();
        frame.setSize(1200,800);
        frame.setTitle("Traffic simulator");
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

        background = new JPanel(new GridBagLayout());
        background.setBackground(Color.lightGray);

        roads = new RoadSystem();
        background.add(roads, new GridBagConstraints(0,0,1,3,0.1,1.0,
                                                         GridBagConstraints.WEST, GridBagConstraints.NONE,
                                                         new Insets(10, 10, 10, 0), 0, 0));

        stats = new Stats();
        background.add(stats, new GridBagConstraints(1,0,1,1,1.0,1.0,
                                                        GridBagConstraints.WEST, GridBagConstraints.BOTH,
                                                        new Insets(10, 0, 10, 10), 0, 0));

        settings = new Settings();
        background.add(settings , new GridBagConstraints(1,1,1,1,1.0,1.0,
                                                         GridBagConstraints.WEST, GridBagConstraints.BOTH,
                                                         new Insets(10, 0, 10, 10), 0, 0));

        startButton = new JButton();
        background.add(startButton, new GridBagConstraints(1,2,1,1,1.0,0.2,
                                                        GridBagConstraints.WEST, GridBagConstraints.BOTH,
                                                         new Insets(10, 0, 10, 10), 0, 0));

        frame.add(background);
    }
JamesCherrill commented: Already answered. This guy is just a non-listening time waster -3

Recommended Answers

All 2 Replies

I already told you what causes this probem and how to fix it.
You are wasting your time and ours by asking the same question twice.