Solved

Java swing panel placement

Posted on 2012-04-11
2
544 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HashTable highest marks enumeration alternative 9 42
web application structure 18 95
check java version using powershell 13 168
Convert from a json string array to a Java object 3 51
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

791 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