That's because of the default behavior of the default layout manager of a JFrame's content pane.
You should be able to figure out which layout manager is used and what the default behavior you get when invoking the add() method with respect to the size of the component you add, if you follow the link to the JFrame's API documentation
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Joined: Sep 29, 2012
Didn't understand, can you post a code example?
I tried it this way, and it shows both, but now the Curve looks very weird(at least not, like at beginning)
The BorderLayout indedd is the default layout manager used by the content pane, and according to its API documentation:
border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component ...
So your approach of adding each component to its own region seems like a reasonable fix, however the API documentation also states:
The components are laid out according to their preferred sizes and the constraints of the container's size. The NORTH and SOUTH components may be stretched horizontally; the EAST and WEST components may be stretched vertically; the CENTER component may stretch both horizontally and vertically to fill any space left over.
What that means is that the Curve (a JPanel) instance will be stretched horizontally, but the preferred height will be respected - if set. The JLabel will be likewise be stretched horizontally in the SOUTH region and the CENTER region will fill whatever size is left to fill the dimensions of the JFrame. You need to ask yourself if the BorderLayout is the most appropriate layout manager for the layout you have in mind. There's a visual guide to layout managers on the Oracle website, which may help you decide.
Actually there are more problems than just the layout manager and I'm not talking about the non descriptive variable and class names or the failure to follow Java naming conventions.
You should never put Thread.sleep() and/or repaint in any of the paintXXX methods. If you want to do animations then you need to use a background thread or Timer to change the components state and call repaint();
Sounds like something which would fit better in our GUIs forum.
You really should start your GUIs very small. Start with a GUI which simply displays a frame. Then you can add to it. If you don’t have a book which describes the graphics, start here, though JavaFX may supersede Swing in a few years. You should find layouts in that tutorial, too.