[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

05/22/2007 at 06:09PM PDT, ID: 22588906
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Help with Layout manager

Asked by omahne in Java Programming Language, New to Java Programming

Tags: help, layout

Ok.  I need to use the right layout manager so when the user resizes the container, all component sizes and positions are adjusted accordingly.  For example,  when the user uses the mouse to enlarge the container, the components should remain at the middle and in the same arrangement .  This is what I have:

import java.awt.*;
import javax.swing.*;

public class NestingOne extends JFrame {

     private JPanel panel1, panel2, panel3;
     private Container container;
     private JButton buttons[];
     private JCheckBox snapgrid, showgrid;
     private GridBagLayout gbl1,gbl2, gbl3;
     private GridBagConstraints c;
     private JTextField field1, field2;
     private JLabel label1, label2;

     public NestingOne(){

          super("Nesting Panels");

          container = getContentPane();
          gbl1 = new GridBagLayout();
          c = new GridBagConstraints();
          c.anchor = GridBagConstraints.WEST;
          c.fill  =  GridBagConstraints.NONE;
          Insets i = new Insets(2,6,6,2);
          c.insets = i;

          c.gridx = 0;
          c.gridy = 0;
          c.weightx = 1.0;
          c.weighty = 1.0;
          c.gridwidth = 1;
          c.gridheight = 1;

          panel1 = new JPanel();
          panel1.setLayout(gbl1);
          snapgrid = new JCheckBox("Snap To Grid");
          gbl1.setConstraints(snapgrid, c);
          panel1.add(snapgrid);

          c.gridy = 1;
          showgrid = new JCheckBox("Show Grid");
          gbl1.setConstraints(showgrid, c);
          panel1.add(showgrid);

          container.add(panel1, BorderLayout.WEST);

//panel 2 layout and add for x and y
          gbl2 = new GridBagLayout();
          panel2 = new JPanel();
          panel2.setLayout(gbl2);

          c.gridy = 0;
          c.anchor = GridBagConstraints.EAST;

          label1 = new JLabel("X: ");
          label2 = new JLabel("Y: ");
          gbl2.setConstraints(label1, c);
          panel2.add(label1);

          c.gridy = 1;
          gbl2.setConstraints(label2, c);
          panel2.add(label2);

          c.gridy = 0;
          c.gridx = 1;
          c.anchor = GridBagConstraints.WEST;

          field1 = new JTextField("8",5);
          gbl2.setConstraints(field1, c);
          panel2.add(field1);

          c.gridy = 1;
          field2 = new JTextField("8",5);
          gbl2.setConstraints(field2, c);
          panel2.add(field2);

          container.add(panel2, BorderLayout.CENTER);

//Panel 3 layout and add for OK, Help, Cancel

       c.anchor = GridBagConstraints.CENTER;
       c.gridx = 0;
       c.gridy = 0;
       c.fill  =  GridBagConstraints.BOTH;

       gbl3 = new GridBagLayout();
       buttons = new JButton[3];
       panel3 = new JPanel();
       panel3.setLayout(gbl3);
       buttons[0] = new JButton("OK");
       gbl3.setConstraints(buttons[0], c);
       panel3.add(buttons[0]);
       buttons[1] = new JButton("Cancel");
       c.gridy = 1;
       gbl3.setConstraints(buttons[1], c);
       panel3.add(buttons[1]);
       buttons[2] = new JButton("Help");
       c.gridy = 2;
       gbl3.setConstraints(buttons[2], c);
       panel3.add(buttons[2]);

       container.add(panel3, BorderLayout.EAST);

       setSize(425,150);
       setVisible(true);
   }
   public static void main(String args[])
   {
       NestingOne application = new NestingOne();

       application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
}

Thanks so very much.

 
[+][-]05/22/07 08:28 PM, ID: 19139191

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, New to Java Programming
Tags: help, layout
Sign Up Now!
Solution Provided By: Javatm
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05/23/07 03:50 AM, ID: 19140523

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/23/07 05:30 PM, ID: 19146023

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74