I have a really hard time with java and its swing components, i must say this was a lot easier when i programmed with C#, and i am a little bit stuck with this code.
What i am trying to do is to add some panels on another panel
.
This to show the user the tasks that needs to be done by the project he joined.
I created a panel on the right side of the Gui, and i want to add more panels to it during runtime. I managed to add one panel to it, but it has some strange behaviors.
The blue panel is the newly created
panel i added during runtime with this code.
JPanel pnl = new JPanel();
lpane.setBackground(Color.red);
lpane.setLayout(new BorderLayout());
pnl.setBounds(0, 0, 20, 100);
pnl.setOpaque(true);
pnl.setBackground(Color.BLUE);
lpane.add(pnl);
lpane.validate();
This is just a test, that's why the code does not contain a for-loop etc for the rest of the panels.
As you can see i am using BorderLayout
because i found this on the internet, and because without BorderLayout it won't draw anything.
Also when i am trying to set the BorderLayout to .NORTH or .STARTPAGE it starts drawing above in the panel but i still can't set any positions of the panel?
Somebody knows why i cannot set any positions or WIDTH and HEIGTH?