Solved

Java swing panel placement

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

911 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

24 Experts available now in Live!

Get 1:1 Help Now