JFrame execution time adding JPanel?

You need to call revalidate() and repaint() after such structural changes to the GUI. Note that setSize and setLocation should preferrably be handled by the layout manager. Related link: jGuru: What is the difference between repaint() and revalidate() in Swing components?

– JMira Sep 15 at 13:23 That depends on how you want the components to be layed out in the frame. If you want the box to have position x,y you should create a custom layout manager, set the content pane to use this manager, and pass x and y to the layout manager when adding the panel. Google for java custom layout manager for instance.

– aioobe Sep 15 at 13:29.

If they are purely visual, and you don't intend to add components to them, it would be better to define a Box class (or use a Rectangle2D) and draw or fill them at time of paintComponent(). Alternately, draw them to the Graphics object of a BufferedImage and add the image to a JLabel, as shown here.

Nice shot to the dark (with fireworks) +1 – mKorbel Sep 15 at 17:12.

This example showing add/remove/pack may help. Private void addBox(int x, int y){ JPanel panel = new JPanel(); panel. SetBackground(Color.

RED); add(panel); //If there isn't another JPanel, then this way you'll occupy //the whole JFrame area; by defalut, JFrame has BorderLayout, //and only one JComponent can occupy the central area revalidate(); repaint(); }.

How do you know he hasn't done getContentPane(). SetLayout(null)? – aioobe Sep 15 at 13:28 @aioobe 1) yes only in case that there is setLayout(null), 2) no for setSize and setLocation, because pretty ignored used LayoutManager and works in all cases – mKorbel Sep 15 at 13:40 ...and works in all cases -- Uhm, the values passed to setSize will be overridden by any layout-manager present (i.e.

Will only be in use until the component needs to be "re-layed-out"). Perhaps that's what you tried to say ;-) – aioobe Sep 15 at 13:52.

You need to call revalidate() and repaint() after such structural changes to the GUI.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions