Solved

Java swing panel placement

Posted on 2012-04-11
2
539 Views
Last Modified: 2013-11-24
Hi,

I've got some weird issue here. Its the first time using swing though.
So the idea is to have a frame with 2 panels:
1 set north with dimensions(500, 500)
1 set south with dimensions(500, 100)
in the north panel a Jcomponent view which fills it up.

So here is the partial code I have:
JFrame.setDefaultLookAndFeelDecorated(true);

            // maak een venster (frame)
            JFrame frame=new JFrame("Mind map");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().setBackground(Color.WHITE);
            frame.setResizable(false);
            frame.setSize(new Dimension(500, 600));
            
            GridLayout layout = new GridLayout(2, 1);
            frame.setLayout(layout);
            
            JPanel panelActorView = new JPanel();
            panelActorView.setBounds(0, 0, 500, 500);
            
            JPanel panelMenu = new JPanel();
            panelMenu.setBounds(0, 500, 500, 100);
            
            frame.add(panelActorView, BorderLayout.NORTH);
            frame.add(panelMenu, BorderLayout.CENTER);

            // voeg een ActorView toe aan het venster
            ActorView view=new ActorView(new Dimension(500, 500));
            panelActorView.add(view);
            
            JButton quitButton = new JButton("Quit");
            quitButton.setBounds(0, 0, 80, 30);
            quitButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    System.exit(0);
               }
            });
            
            panelMenu.add(quitButton);

            // toon het venster
            frame.pack();
            frame.setVisible(true);

Open in new window


as of now I have setBounds for both panels, but I also tried setSize(), setMaximumSize(), setPreferedSize(), ...

None of these works. The problem i have is that both panels use the dimensions of my ActorView (JComponent).

Any ideas why?
0
Comment
Question by:Mutsop
2 Comments
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
ID: 37831398
try commenting frame.setLayout(layout);

the issue is you are trying to set BorderLayout dimension but you have set GridLayout!
0
 
LVL 3

Author Closing Comment

by:Mutsop
ID: 37831410
Well that seems to work :)
Thanks alot

If there are any better options, I'm still open for it !
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now