[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.

Question
[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!

6.2

JPanel not fitting TabbedPane

Asked by Drop_of_Rain in Java Programming Language, Java AWT & Swing

Tags: fitting, gridlayout, jpanels

Why does this JPanel fill up the TabbedPane. While the JPanel Below this one doesn't. Can someone help me with this.

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



public class TraineeInfo extends JPanel implements ActionListener
{ // Opens class

           
     
     
     // Text fields for user input
     private JTextField name;
     private JTextField street;
     private JTextField city;
     private JTextField statezip;  
             
     // Labels to go with each text field
     private JLabel lname;
     private JLabel lstreet;
     private JLabel lcity;
     private JLabel lstatezip;          
           
     // Check boxes for types of training
     private JCheckBox ow;
     private JCheckBox a;
     private JCheckBox res;
     private JCheckBox un;
     private JCheckBox w;
             
     // Textfields for Emergency box
     private JTextField nname;
     private JTextField phone;
     private JTextField rel;
     
     // Textfields for Emergency Contact
     private JLabel lnname;
     private JLabel lphone;
     private JLabel lrel;
     
     // Buttons and image
     private JButton enter;
     private JButton edit;
     private JLabel seahorse;
             
     // Panels to be built and added
     // to the border layout of this
     // panel.
             
     private JPanel images;
     private JPanel jaddress;
     private JPanel emerg;
     private JPanel training;
             
     // Class to handle functionality of checkboxes  
     ItemListener handler = new CheckBoxHandler();
             
                         
     // Class constructor that builds the necessary
     // labels and text fields images, buttons,
     // and panels.        
         
          public TraineeInfo()
            { // Opens Constructor
             // Sets layout for Trainee panel
             setLayout(new BorderLayout());
             // Sets background color for
             // Diver panel
             setBackground(Color.white);
             
             // Initializes textfields
             name = new JTextField("Enter Your Name");
             street = new JTextField();
             city = new JTextField ();
             statezip = new JTextField ();
             // Initializes labels for textfields
             lname = new JLabel("Name: ");
             lstreet = new JLabel("Street: ");
             lcity = new JLabel ("City: ");
             lstatezip = new JLabel("State & Zip Code: ");
             // Initializes checkboxes with titles
             ow = new JCheckBox("Beginner", true);
             a = new JCheckBox("Advanced");
             res = new JCheckBox("Accomplished");
             un = new JCheckBox("Teacher Trainer");
             w = new JCheckBox("Teacher");
             
             // Initializes textfields for emergency panel
             nname = new JTextField();
             phone = new JTextField();
             rel = new JTextField ();
             // Initializes labels for textfields
             lnname = new JLabel("Name: ");
             lphone = new JLabel("Phone: ");
             lrel = new JLabel ("Relationship: ");
             // Initialize objects
             enter = new JButton("Enter Diver Data");
             edit = new JButton("Edit Diver Data");
             seahorse = new JLabel("",  
                  new ImageIcon("images/2seahorses.jpg"),
                                          JLabel.CENTER);
             // Calls method to buid image panel, which
             // is defined outside of the constructor
             buildImagePanel();    
             
             // Calls method to buid address panel, which
             // is defined outside of the constructor        
             buildAddressPanel();
             
             // Calls method to buid emerg panel, which
             // is defined outside of the constructor
             buildEmergencyPanel();
             
             // Calls method to buid training panel, which
             // is defined outside of the constructor
             buildTrainingPanel();
             
           //The methods called above build the panels, then this
          // call to add adds each panel to the main panel's
          // border layout manager.
     
           add(jaddress, BorderLayout.NORTH);
           add(images, BorderLayout.CENTER);
           add(training, BorderLayout.EAST);
           add(emerg, BorderLayout.SOUTH);
       
       
        } // Ends constructor
       
       
        // This method creates a panel called images
        private void buildImagePanel()
        { // Opens method
           images = new JPanel();
          // Sets the color, layout, and adds the
          // seahorse object
           images.setBackground(Color.white);
           images.setLayout(new FlowLayout() );
           images.add(seahorse);
          } // Closes method
       
        private void buildAddressPanel ()
        { // Opens method
          jaddress = new JPanel();
          // Sets color and layout.
          // Adds the textfields and labels for
          // diver input.
          jaddress.setBackground(Color.white);
          jaddress.setLayout( new  GridLayout(2, 4, 20, 20) );
          //Adds each component to the panel
          jaddress.add(lname);
          jaddress.add(name);
          jaddress.add(lstreet);
          jaddress.add(street);
          jaddress.add(lcity);  
          jaddress.add(city);  
          jaddress.add(lstatezip);  
          jaddress.add(statezip);
 
          // Sets a border around the panel, including
          // a title
          jaddress.setBorder(BorderFactory.createTitledBorder(
                                    "Diver Personal Information"));
             
          //Listeners for each text field in the
          name.addActionListener( this );
          street.addActionListener( this );
          city.addActionListener( this );
          statezip.addActionListener( this );
           
        } // Closes method
       
        private void buildEmergencyPanel()
         { // Opens method
          //Create another panel for emergency input fields
            emerg = new JPanel();
            emerg.setLayout( new  GridLayout(2, 4, 20, 0) );
            emerg.setBackground(Color.white);
         
            emerg.add( lnname);
            emerg.add( nname);
            emerg.add( lphone);
            emerg.add( phone);
            emerg.add( lrel);  
            emerg.add( rel);
            emerg.add(enter);
            emerg.add(edit);
           //Creates titled border around emerg panel
            emerg.setBorder(BorderFactory.createTitledBorder("Emergency"));

            //Adds an actionListener for Emergency Info
            nname.addActionListener( this );
            phone.addActionListener( this );
            rel.addActionListener( this );
           
           
            //Creates borders around the Edit and
            // Enter Diver Data buttons
            enter.setBorder(BorderFactory.createRaisedBevelBorder());
            edit.setBorder(BorderFactory.createRaisedBevelBorder());
     
             //Listeners for the buttons
             enter.addActionListener( this );
             edit.addActionListener( this );
            } //Closes method
       
        private void buildTrainingPanel()
        { //Opens method
       
          // Creates a panel for training courses
     
           training = new JPanel();
           training.setBackground(Color.white);
           training.setLayout(new GridLayout(5, 1, 10, 20 ) );
           //sets backgrounds of components to white
           training.add(ow).setBackground(Color.white);
           training.add(a).setBackground(Color.white);
           training.add(un).setBackground(Color.white);
           training.add(res).setBackground(Color.white);
           training.add(w).setBackground(Color.white);
       
          //Sets a titled border around training panel
          training.setBorder(BorderFactory.createTitledBorder("Training"));
          //Adds listeners to checkbox items
            ow.addItemListener(handler);
            a.addItemListener(handler);
            un.addItemListener(handler);
            res.addItemListener(handler);
            w.addItemListener(handler);
         } //Closes method
     
      // Prints the input into JLabels and hides text fields, or
      // returns the text fields so input may be changed
   
      public void actionPerformed(ActionEvent evt)
        { // Opens method
        // Checks if the button clicked was the
        // Enter Diver Data button.
        // If not, moves on to next if statment.
        // Otherwise it enters this if statement
        if ((evt.getSource() == name) || (evt.getSource() == enter))
             { // Opens if statement
              //Retrives the text from the name text field and
              //assigns it to the variable nameText of
              //type String
              String nameText = name.getText();
              lname.setText("Name:    " + nameText);
              //After printing text to JLabel, hides the textfield
              name.setVisible(false);
              }// ends if statement
        if ((evt.getSource() == street) || (evt.getSource() == enter))
             { // Opens if statement                        
              String streetText = street.getText();
              lstreet.setText("Street:    " + streetText);
              street.setVisible(false);
               }// ends if statement  
         if ((evt.getSource() == city) || (evt.getSource() == enter))  
             { // Opens if statement          
              String cityText = city.getText();
              lcity.setText("City:  " + cityText);
              city.setVisible(false);
                   }// ends if statement        
         if ((evt.getSource() == statezip) || (evt.getSource() == enter))
             { // Opens if statement            
              String statezipText = statezip.getText();
              lstatezip.setText("State & Zip:     " + statezipText);
              statezip.setVisible(false);
                   }// ends if statement        
        if ((evt.getSource() == nname) || (evt.getSource() == enter))
             { // Opens if statement            
              String relname = nname.getText();
              lnname.setText("Name:   " + relname);
              nname.setVisible(false);
                    }// ends if statement        
        if ((evt.getSource() == phone) || (evt.getSource() == enter))
             { // Opens if statement              
              String relphone = phone.getText();
              lphone.setText("Phone:   " + relphone);
              lphone.setForeground(Color.red);
              phone.setVisible(false);
              }
        if ((evt.getSource() == rel) || (evt.getSource() == enter))  
        {            
              String relString = rel.getText();
              lrel.setText("Relationship:   " + relString);
              rel.setVisible(false);
   
 
          // If Edit button was clicked, set textfields to
          // visible for user to reenter information and
          // it sets the text that had been entered to
          // to an empty String, giving the appearance
          // that the text has been removed.  
          } // Closes if statement
           if (evt.getSource() == edit)
              { // Opens else if statement
       
           // If edit button has been pressed
           // the following is set to visible
            name.setVisible(true);
            street.setVisible(true);
            city.setVisible(true);
            statezip.setVisible(true);
           
            // Relative's info
           
            nname.setVisible(true);
            phone.setVisible(true);
            rel.setVisible(true);
           
            lnname.setText("Name:   ");
            lnname.setForeground(Color.black);
            lphone.setText("Phone:   ");
            lphone.setForeground(Color.black);
            lrel.setText("Relationship:   ");
            lrel.setForeground(Color.black);
       
         } // Ends if statement
       
        } // Ends actionPerformed method

 // Inner class that handles functionality for the
 // checkboxes.
 private class CheckBoxHandler implements ItemListener
 { // Opens inner class
       
      public void itemStateChanged (ItemEvent e)
        { // Opens method
               // Retrieves object that fires an
               // event, casts it as a JCheckBox
               // object and assigns it to source.
               JCheckBox source = (JCheckBox) e.getSource();
               // If the object is selected . . .
               if ( e.getStateChange() == ItemEvent.SELECTED )
                 // change the foreground to blue
                 source.setForeground(Color.blue);
                 // otherwise set the foreground to black.
               else
                 source.setForeground(Color.black);
             
             } // Closes ItemStateChanged method
      } // Closes class CheckBoxHandler
 
 
     
  } // Closes Class Trainee




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

public class Kempos extends JPanel
{ // Opens class

    public Kempos()
    {
        super();

        Font f1 = new Font("Courier New", Font.BOLD, 15);

        JPanel p1 = new JPanel();
        JPanel p2 = new JPanel();
        JPanel p3 = new JPanel();
        JPanel p4 = new JPanel();
        JPanel p5 = new JPanel();

        final JButton b1 = new JButton("G1");
        final JButton b2 = new JButton("G2");
        final JButton b3 = new JButton("G3");
        final JButton b4 = new JButton("G4");
        final JButton b5 = new JButton("G5");
        final JButton b6 = new JButton("G6");
        final JButton b7 = new JButton("G7");
        final JButton b8 = new JButton("G8");

        final JLabel l1 = new JLabel();
        l1.setBorder(BorderFactory.createLineBorder(Color.yellow));

        p1.setBorder(BorderFactory.createLoweredBevelBorder());
        p4.setBorder(BorderFactory.createLoweredBevelBorder());
        p4.setBackground(Color.blue);

        p1.setLayout(new GridLayout(1,2));
        p1.add(p2); p1.add(p3);

        p2.setLayout(new GridLayout(1,1));
        p2.add(p4);

        p4.setLayout(new GridLayout(3,3));
        p4.add(b1); p4.add(b2); p4.add(b3);
        p4.add(b4); p4.add(l1); p4.add(b5);
        p4.add(b6); p4.add(b7); p4.add(b8);

        p5.setLayout(new GridLayout(5,1));
        p5.add(new JLabel("Name 1\n"));
        p5.add(new JLabel("Name 2"));
        p5.add(new JLabel("Name 3"));
        p5.add(new JLabel("Name 4"));
        p5.add(new JLabel("Name 5"));
 
        p3.setLayout(new GridLayout(1,3));
        p3.add(new JPanel()); p3.add(p5);
        p3.add(new JPanel());

        add(p1, BorderLayout.CENTER);

        // Add your action listener here . . .
        b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G1       ");
        b1.setText("");
        b1.setEnabled(false);
        }
        });

        b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G2       ");
        b2.setText("");
        b2.setEnabled(false);
        }
        });

        b3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G3       ");
        b3.setText("");
        b3.setEnabled(false);
        }
        });

        b4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G4       ");
        b4.setText("");
        b4.setEnabled(false);
        }
        });

        b5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G5       ");
        b5.setText("");
        b5.setEnabled(false);
        }
        });

        b6.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G6       ");
        b6.setText("");
        b6.setEnabled(false);
        }
        });

        b7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G7       ");
        b7.setText("");
        b7.setEnabled(false);
        }
        });

        b8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent h)
        {
        l1.setText("       G8       ");
        b8.setText("");
        b8.setEnabled(false);
        }
        });
    }
}

 
[+][-]03/29/04 11:00 PM, ID: 10711221Accepted Solution

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, Java AWT & Swing
Tags: fitting, gridlayout, jpanels
Sign Up Now!
Solution Provided By: zzynx
Participating Experts: 2
Solution Grade: A
 
[+][-]03/29/04 01:29 AM, ID: 10702569Expert Comment

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.

 
[+][-]03/29/04 01:33 AM, ID: 10702581Expert Comment

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.

 
[+][-]03/29/04 01:41 AM, ID: 10702608Author Comment

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.

 
[+][-]03/29/04 01:45 AM, ID: 10702617Author Comment

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.

 
[+][-]03/29/04 01:45 AM, ID: 10702618Expert Comment

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.

 
[+][-]03/29/04 01:47 AM, ID: 10702624Author Comment

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.

 
[+][-]03/29/04 01:49 AM, ID: 10702632Expert Comment

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.

 
[+][-]03/29/04 01:55 AM, ID: 10702649Expert Comment

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.

 
[+][-]03/29/04 01:56 AM, ID: 10702651Author Comment

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.

 
[+][-]03/29/04 02:01 AM, ID: 10702676Author Comment

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.

 
[+][-]03/29/04 02:05 AM, ID: 10702694Expert Comment

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.

 
[+][-]03/29/04 02:07 AM, ID: 10702705Expert Comment

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.

 
[+][-]03/29/04 02:15 AM, ID: 10702745Author Comment

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.

 
[+][-]03/29/04 03:04 AM, ID: 10702972Expert Comment

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.

 
[+][-]03/29/04 08:49 AM, ID: 10705624Author Comment

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.

 
[+][-]03/29/04 12:27 PM, ID: 10707594Expert Comment

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.

 
[+][-]03/29/04 10:30 PM, ID: 10711093Author Comment

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.

 
[+][-]03/29/04 11:20 PM, ID: 10711324Author Comment

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.

 
[+][-]03/29/04 11:27 PM, ID: 10711350Expert Comment

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.

 
[+][-]03/29/04 11:34 PM, ID: 10711376Author Comment

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.

 
[+][-]03/29/04 11:44 PM, ID: 10711423Expert Comment

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.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy