Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java swing panel placement

Posted on 2012-04-11
2
Medium Priority
?
552 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This video teaches viewers about errors in exception handling.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

877 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