Solved

Java swing panel placement

Posted on 2012-04-11
2
547 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

615 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