I'm new here and I am in a beginner's java programming class. Our project is to create a simple GUI and then set up classes and simple functionality. In Java 1, I created a simple Java GUI and I am adding to this project for the final in Java 2 project.
I am working with BoderLayout manager with a plan of adding a few Main JPanels, then inside those JPanels, add my components (images, radiobuttons, checkboxes). I would use the borderlayout inside the JPanel to configure the positions. I've added a few border and color changes in my GUI just help me see where everything is at.
I added two images; upperIntelJPanel and amdMainJPanel, but I can't make the images move. I've tried using the LayoutManager and also setBounds, but eitherway they just show in the center and top of my JPanels. I thought I was able to add a JPanel inside another JPanel and use the layout manager to position the component, but maybe I am wrong in my assumption?
This thread is more suited to the Swing forum so I'll move it there for you.
Joined: Aug 07, 2007
To confirm your thoughts on nesting JPanels, yes you can nest them as deep as you want and each JPanel can have a different type of layout manager. But if you want your nested JPanels to layout components using a different layout manager than FlowLayout (which is the default) you need to specify the LayoutManager you want the JPanel to use. You can pass an instance of the appropriate layout manager to the constructor or the JPanel's setLayout() method.
Brent Van Scoy
Joined: Dec 10, 2013
I think that is my issue. I thought the default was BorderLayout, but if it is FlowLayout, that makes sense why it is not working. I will try specifing the layoutmanager for the Jpanel.
I added the below code and I have control of the components again.