0

I was just having a problem with this:

public class Sales extends JPanel{
    ArrayList<JPanel> panes;
    ArrayList<String> tabs;
    JTabbedPane tp;
    public Sales(Dimension d){
        setSize(d);
        setLayout(null);
        tp = new JTabbedPane();
        Font f = new Font("Arial",Font.PLAIN,32);
        tp.setFont(f);
        for(Menu menu : FileManager.menus){
            JPanel tmp = new JPanel();
            /*int s = (int) Math.ceil(Math.sqrt(menu.products.size()));
            tmp.setLayout(new GridLayout(s,s));
            System.out.println("size" + s);
            for(Product p : menu.products){
                p.setFont(f);
                tmp.add(p);
            }*/
            tp.addTab(menu.name,null,tmp,"What is this?");
        }
        tp.setBounds(0,0,getWidth(),getHeight());
        add(tp);
    }
}

Where Sales is just added to a simple JFrame:

public Main(){
        super("HoboGames Pos System");
        setUndecorated(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);
        sale = new Sales(getSize());
        add(sale);
    }

Everything works, except the components don't paint until the window is updated because of a click or something. So it's a blank screen until you click stuff.(Sorry, I cut some corners on things like making it full screen...)

csga5000
  • 4,062
  • 4
  • 39
  • 52
  • Please edit your question to include an [sscce](http://sscce.org/) that exhibits the problem you describe. – trashgod Feb 20 '13 at 23:50

1 Answers1

2

They don't update because you've made the window visible before you've finished adding components to it.

Try something like...

GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);
sale = new Sales(getSize());
add(sale);
setVisible(true);

Alternatively, you could call revalidate and repaint on the frame after you've finished adding your components, but to be honest, it's simpler the first way.

Side Note

Using setSize on a component is strongly discouraged, you should be relying an appropriate layout managed, like BorderLayout to make the decision about the size of the component.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366