There are some problems in your code :
Firstly, if using
frame.setLayout(new FlowLayout(FlowLayout.LEFT));(FlowLayout) then here
frame.getContentPane().add(toolBar.createToolBar(), BorderLayout.NORTH); why are you specifying
BorderLayout.NORTH which has no effect
again case with
frame.getContentPane().add(LabelCreator.createLabel(frame, "Java Swing", "purple"),BorderLayout.NORTH);
contentpane problem, firstly looking at following code(demo) :
JFrame frame= new JFrame(); frame.getContentPane().setBackground(Color.red); frame.getContentPane().setPreferredSize(new Dimension(width, height)); frame.pack(); frame.setVisible(true);
When you pass different values for
height you will see whole size of
frame will get effected as i have not specified
setSize anywhere, the reason for this is
To appear onscreen, every GUI component must be part of a containment hierarchy. A containment hierarchy is a tree of components that has a top-level container as its root. We'll show you one in a bit.
Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the first container and then added to the second.
Each top-level container has a content pane that, generally speaking, contains (directly or indirectly) the visible components in that top-level container's GUI.
You can optionally add a menu bar to a top-level container. The menu bar is by convention positioned within the top-level container, but outside the content pane. Some look and feels, such as the Mac OS look and feel, give you the option of placing the menu bar in another place more appropriate for the look and feel, such as at the top of the screen.
So the conclusion is that changing
contentpane size will change
As your statement
frame.setContentPane(ContentPaneCreator.createContentPane("darkseagreen", 800, 255)); is making the
contentpane, so again changing its size is to change
But the other way around is :
frame.getContentPane().add(ContentPaneCreator.createContentPane("darkseagreen", 800, 255));
jframe and then
add your components to that
container( jpanel in your case )
Hope this will help and one thing more i also used to code like you creating
classes for every little purpose, but sometimes they raise complexities instead of simplicity, so my suggestion to you is to follow a design pattern like
MVC or anyother you like