Reputation: 13
I Want to add a JPanel map on top of another JPanel WorldView in it's center just like this
Here is my Code:
public class WorldView extends JPanel implements ActionListener{
private JPanel map;
public WorldView() throws IOException{
this.setSize(1024,768);
this.setBackground(Color.BLACK);
map = new JPanel();
this.add(map);
}
Upvotes: 0
Views: 238
Reputation: 347204
You could use a GridBagLayout
and modify the GridBagConstraints#insets
or a EmptyBorder
to generate the whitespace around the component in combination with GridBagLayout
or some other layout like BorderLayout
for example
See How to Use GridBagLayout and How to Use Borders for more details
Upvotes: 1
Reputation: 14
Add this in the constrctor : setLayout(new FlowLayout(FlowLayout.CENTER));
Upvotes: 0