Solved

My swing gui the size of buttons and textfields are stretched too big?

Posted on 2006-07-08
11
446 Views
Last Modified: 2013-11-23
I'm designing a gui and i'm having trouble trying to get everything to a decent size. I'd like some rows to have a set size so buttons don't stretch to insane sizes. I'v tried setprefferedsize() and setmaximumsize on these with no luck have a look at the snap shot of my gui. see how huge those top buttons are. Please help!

http://www.southbaybeagles.com/craigslist/example.jpg




i''ll attach my code


import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;

import com.sun.media.sound.Toolkit;

public class movieFrontGui extends JFrame implements ActionListener
{
      JFrame frame;
      JPanel panelGenre;
      JPanel panelQuickJump;
      JPanel panelMoviesArea;
      JPanel panelToolbar;
      JPanel bottomPanel;
      
      
      List list;
      
      
      JTable table;
      
      
      JTextField search_textfield;
      
      
      //======Buttons=============
      JButton button_search;
      JButton button_addMovie;
      JButton button_deleteMovie;
      JButton button_editMovie;
      JButton button_all;
      JButton[] quickButtons = new JButton[26];
              
              
      JButton button_a;
      JButton button_b;
      JButton button_c;
      JButton button_d;
      JButton button_e;
      JButton button_f;
      JButton button_g;
      JButton button_h;
      JButton button_i;
      JButton button_j;
      JButton button_k;
      JButton button_l;
      JButton button_m;
      JButton button_n;
      JButton button_o;
      JButton button_p;
      JButton button_q;
      JButton button_r;
      JButton button_s;
      JButton button_t;
      JButton button_u;
      JButton button_v;
      JButton button_w;
      JButton button_x;
      JButton button_y;
      JButton button_z;
      
      JMenu file_menu;
      JMenuItem file_save;
      JMenuItem file_saveAs;
      JMenuItem file_exit;
      
      
      JMenu view_menu;
      
      JMenu help_menu;
      
      JMenuBar menuBar;
      

      movieFrontGui()
      {
            
            createGui();
            
      
      }
      

      void createGui()
      {
            frame = new JFrame("Movie Warehouse");
            frame.setSize(1280,1024);     //<============need to dynamicly set size!
            createPanelQuickJump();
            createPanelToolBar();
            createMenuBar();
            createpanelGenre();
            creatpanelMoviesArea();
            
            //merge movies area and genre into one JPanel
            bottomPanel = new JPanel();
            bottomPanel.add(panelGenre);
            bottomPanel.add(panelMoviesArea);
            
            frame.setLayout(new GridLayout(3,1));
            //frame.getContentPane().add(menuBar);
            frame.getContentPane().add(panelToolbar);
            frame.getContentPane().add(panelQuickJump);
            frame.getContentPane().add(bottomPanel);
        frame.setLocationRelativeTo( null );         // Center the frame on the screen.
        frame.setVisible( true );  
        frame.pack();
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        // Make the frame visible to the user.              // Make the frame visible to the user.
            /*
            panelQuickJump;
            panelMoviesArea;
            panelToolbar;
            */
            
            
            
      }
      
      void createMenuBar()
      {
            //====File menu================
            file_menu = new JMenu("File");
            file_menu.add(file_save = new JMenuItem("Save"));
            file_menu.add(file_saveAs = new JMenuItem("Save As"));
            file_menu.add(file_exit = new JMenuItem("Exit"));
            
            
            //====View Menu================
            view_menu = new JMenu("View");
            
            //=Help Menu=================
            help_menu = new JMenu("Help");
            
            menuBar = new JMenuBar();
            
            menuBar.add(file_menu);
            menuBar.add(view_menu);
            menuBar.add(help_menu);
        frame.setJMenuBar(menuBar);

            
      }
      
      void createPanelQuickJump()
      {
            panelQuickJump = new JPanel();
            panelQuickJump.setLayout(new GridLayout(1,26));
          createQuickButtons();
            
            
      }
      
      void creatpanelMoviesArea()
      {
            panelMoviesArea = new JPanel();
            table = new JTable(20,4);
            
            panelMoviesArea.add(table);
            
      }
      void createpanelGenre()
      {
            list = new List();
            list.add("All");
            list.add("Action");
            list.add("Adventure");
            list.add("Animation");
            list.add("Comedy");
            list.add("Documentary");
            list.add("Drama");
            list.add("Horror");
            list.add("Sci-Fi");
            list.add("Suspense");
            list.add("Tv");
            
            
            panelGenre = new JPanel();
            panelGenre.add(list);
            
      
      }
      void createPanelToolBar()
      {
            panelToolbar = new JPanel();
            panelToolbar.setLayout(new GridLayout(1,6));
            search_textfield = new JTextField();
            JLabel labelSearch = new JLabel("Search");
            panelToolbar.add(labelSearch);
            panelToolbar.add(search_textfield);
            panelToolbar.add(button_search);
            panelToolbar.add(button_addMovie);
            panelToolbar.add(button_deleteMovie);
            panelToolbar.add(button_editMovie);
      }
      
      void createQuickButtons()
      {
            button_all = new JButton("all");
            button_all.addActionListener(this);
            panelQuickJump.add(button_all);
            //alphabet buttons
            for(int i=0; i < 26; i++)
            {
                  char string= 'a';
                  quickButtons[i] = new JButton("a");
                  quickButtons[i].addActionListener(this);
                  panelQuickJump.add(quickButtons[i]);
            }
            
            //other buttons
            button_search = new JButton("Search");
            button_search.addActionListener(this);
          button_addMovie = new JButton("Add Movie");
          button_addMovie.addActionListener(this);
          button_deleteMovie = new JButton("Delete Movie");
          button_deleteMovie.addActionListener(this);
          button_editMovie = new JButton("Edit Movie");
          button_editMovie.addActionListener(this);
      }

      /**
    Performs the specific actions once a listener is invoked
    */
    public void actionPerformed(ActionEvent actionevent)
    {
          
    }
      
      
      
    public static void main(String args[])
    {
        movieFrontGui dogfiler = new movieFrontGui();
     
    }
      
      
      
      
      
}

            
            
            
            
            
            
0
Comment
Question by:tyweed420
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Set a FlowLayout on each button panel
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
>           panelQuickJump.setLayout(new GridLayout(1,26));

GridLayout ignores the preferred size, try commenting that line out.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
same with your other button panels
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>try commenting that line out.

i.e. use a FlowLayout (the default)
0
 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
I would suggest combination of BorderLayout and GridBagLayout for your UI to get a better control!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
try this out,

    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.JTextField;

    import com.sun.media.sound.Toolkit;

    public class TestLayout extends JFrame implements ActionListener
    {
         JFrame frame;
         JPanel panelGenre;
         JPanel panelQuickJump;
         JPanel panelMoviesArea;
         JPanel panelToolbar;
         JPanel bottomPanel;


         List list;


         JTable table;


         JTextField search_textfield;


         //======Buttons=============
         JButton button_search;
         JButton button_addMovie;
         JButton button_deleteMovie;
         JButton button_editMovie;
         JButton button_all;
         JButton[] quickButtons = new JButton[26];


         JButton button_a;
         JButton button_b;
         JButton button_c;
         JButton button_d;
         JButton button_e;
         JButton button_f;
         JButton button_g;
         JButton button_h;
         JButton button_i;
         JButton button_j;
         JButton button_k;
         JButton button_l;
         JButton button_m;
         JButton button_n;
         JButton button_o;
         JButton button_p;
         JButton button_q;
         JButton button_r;
         JButton button_s;
         JButton button_t;
         JButton button_u;
         JButton button_v;
         JButton button_w;
         JButton button_x;
         JButton button_y;
         JButton button_z;

         JMenu file_menu;
         JMenuItem file_save;
         JMenuItem file_saveAs;
         JMenuItem file_exit;


         JMenu view_menu;

         JMenu help_menu;

         JMenuBar menuBar;


         TestLayout()
         {

              createGui();


         }


         void createGui()
         {
              frame = new JFrame("Movie Warehouse");
              frame.setSize( 800, 600 );     //<============need to dynamicly set size!
              createPanelQuickJump();
              createPanelToolBar();
              createMenuBar();
              createpanelGenre();
              creatpanelMoviesArea();

              //merge movies area and genre into one JPanel
              bottomPanel = new JPanel();
              bottomPanel.add(panelGenre);
              bottomPanel.add(panelMoviesArea);

//              frame.getContentPane().setLayout(new GridLayout(3,1));
             JPanel pnlButton = new JPanel( new GridBagLayout() ) ;
             pnlButton.add( panelToolbar, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0 ), 0, 0 ) ) ;
             pnlButton.add( panelQuickJump, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0 ), 0, 0 ) ) ;
//             pnlButton.setPreferredSize( new Dimension( 600, 150 ) );
              //frame.getContentPane().add(menuBar);
              frame.getContentPane().add(pnlButton, BorderLayout.NORTH);
//              frame.getContentPane().add(panelQuickJump);
              frame.getContentPane().add(bottomPanel);
            frame.setLocationRelativeTo( null );         // Center the frame on the screen.
            frame.setVisible( true );
            frame.pack();
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);

            // Make the frame visible to the user.              // Make the frame visible to the user.
              /*
              panelQuickJump;
              panelMoviesArea;
              panelToolbar;
              */



         }

         void createMenuBar()
         {
              //====File menu================
              file_menu = new JMenu("File");
              file_menu.add(file_save = new JMenuItem("Save"));
              file_menu.add(file_saveAs = new JMenuItem("Save As"));
              file_menu.add(file_exit = new JMenuItem("Exit"));


              //====View Menu================
              view_menu = new JMenu("View");

              //=Help Menu=================
              help_menu = new JMenu("Help");

              menuBar = new JMenuBar();

              menuBar.add(file_menu);
              menuBar.add(view_menu);
              menuBar.add(help_menu);
            frame.setJMenuBar(menuBar);


         }

         void createPanelQuickJump()
         {
              panelQuickJump = new JPanel();
              panelQuickJump.setLayout( new GridBagLayout() );
             createQuickButtons();


         }

         void creatpanelMoviesArea()
         {
              panelMoviesArea = new JPanel();
              table = new JTable(20,4);

              panelMoviesArea.add(table);

         }
         void createpanelGenre()
         {
              list = new List();
              list.add("All");
              list.add("Action");
              list.add("Adventure");
              list.add("Animation");
              list.add("Comedy");
              list.add("Documentary");
              list.add("Drama");
              list.add("Horror");
              list.add("Sci-Fi");
              list.add("Suspense");
              list.add("Tv");


              panelGenre = new JPanel();
              panelGenre.add(list);


         }
         void createPanelToolBar()
         {
              panelToolbar = new JPanel();
              panelToolbar.setLayout( new GridBagLayout() );
              search_textfield = new JTextField( 10 );
              JLabel labelSearch = new JLabel("Search");
              panelToolbar.add(labelSearch, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(search_textfield, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_search, new GridBagConstraints( 2, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_addMovie, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_deleteMovie, new GridBagConstraints( 4, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_editMovie, new GridBagConstraints( 5, 0, 1, 1, 1.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
         }

         void createQuickButtons()
         {
              button_all = new JButton("all");
              button_all.addActionListener(this);
              panelQuickJump.add(button_all, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));

              //alphabet buttons
              for(int i=0; i < 26; i++)
              {
                   char string= 'a';
                   quickButtons[i] = new JButton("a");
                   quickButtons[i].addActionListener(this);
                   panelQuickJump.add(quickButtons[i], new GridBagConstraints( GridBagConstraints.RELATIVE, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              }

              //other buttons
              button_search = new JButton("Search");
              button_search.addActionListener(this);
             button_addMovie = new JButton("Add Movie");
             button_addMovie.addActionListener(this);
             button_deleteMovie = new JButton("Delete Movie");
             button_deleteMovie.addActionListener(this);
             button_editMovie = new JButton("Edit Movie");
             button_editMovie.addActionListener(this);
         }

         /**
        Performs the specific actions once a listener is invoked
        */
        public void actionPerformed(ActionEvent actionevent)
        {

        }



        public static void main(String args[])
        {
            TestLayout dogfiler = new TestLayout();

        }





    }
0
 

Author Comment

by:tyweed420
Comment Utility
The flowlayout worked but what about my jlist it stays super small i'd like it long so you can see everything on the list. I eagerly await your responses. Oh i tried setpreferredsize and setminimumsize neither did anything?
0
 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
use GridBagLayout to setpreferredsize and setminimumsize to work!
0
 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
and see if this is what u needed,

import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

import javax.swing.*;

    public class TestLayout extends JFrame implements ActionListener
    {
         JFrame frame;
         JPanel panelGenre;
         JPanel panelQuickJump;
         JPanel panelMoviesArea;
         JPanel panelToolbar;
         JPanel bottomPanel;


         List list;


         JTable table;


         JTextField search_textfield;


         //======Buttons=============
         JButton button_search;
         JButton button_addMovie;
         JButton button_deleteMovie;
         JButton button_editMovie;
         JButton button_all;
         JButton[] quickButtons = new JButton[26];


         JButton button_a;
         JButton button_b;
         JButton button_c;
         JButton button_d;
         JButton button_e;
         JButton button_f;
         JButton button_g;
         JButton button_h;
         JButton button_i;
         JButton button_j;
         JButton button_k;
         JButton button_l;
         JButton button_m;
         JButton button_n;
         JButton button_o;
         JButton button_p;
         JButton button_q;
         JButton button_r;
         JButton button_s;
         JButton button_t;
         JButton button_u;
         JButton button_v;
         JButton button_w;
         JButton button_x;
         JButton button_y;
         JButton button_z;

         JMenu file_menu;
         JMenuItem file_save;
         JMenuItem file_saveAs;
         JMenuItem file_exit;


         JMenu view_menu;

         JMenu help_menu;

         JMenuBar menuBar;


         TestLayout()
         {

              createGui();


         }


         void createGui()
         {
              frame = new JFrame("Movie Warehouse");
              frame.setSize( 800, 600 );     //<============need to dynamicly set size!
              createPanelQuickJump();
              createPanelToolBar();
              createMenuBar();
              createpanelGenre();
              creatpanelMoviesArea();

              //merge movies area and genre into one JPanel
              bottomPanel = new JPanel();
//              bottomPanel.add(panelGenre);
              bottomPanel.add(panelMoviesArea);

//              frame.getContentPane().setLayout(new GridLayout(3,1));
             JPanel pnlButton = new JPanel( new GridBagLayout() ) ;
             pnlButton.add( panelToolbar, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0 ), 0, 0 ) ) ;
             pnlButton.add( panelQuickJump, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0 ), 0, 0 ) ) ;
//             pnlButton.setPreferredSize( new Dimension( 600, 150 ) );
              //frame.getContentPane().add(menuBar);
             frame.getContentPane().add(pnlButton, BorderLayout.NORTH);
//              frame.getContentPane().add(panelQuickJump);
              frame.getContentPane().add( new JScrollPane( table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ) );
             frame.getContentPane().add( new JScrollPane( list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ), BorderLayout.WEST );
            frame.setLocationRelativeTo( null );         // Center the frame on the screen.
            frame.setVisible( true );
            frame.pack();
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);

            // Make the frame visible to the user.              // Make the frame visible to the user.
              /*
              panelQuickJump;
              panelMoviesArea;
              panelToolbar;
              */



         }

         void createMenuBar()
         {
              //====File menu================
              file_menu = new JMenu("File");
              file_menu.add(file_save = new JMenuItem("Save"));
              file_menu.add(file_saveAs = new JMenuItem("Save As"));
              file_menu.add(file_exit = new JMenuItem("Exit"));


              //====View Menu================
              view_menu = new JMenu("View");

              //=Help Menu=================
              help_menu = new JMenu("Help");

              menuBar = new JMenuBar();

              menuBar.add(file_menu);
              menuBar.add(view_menu);
              menuBar.add(help_menu);
            frame.setJMenuBar(menuBar);


         }

         void createPanelQuickJump()
         {
              panelQuickJump = new JPanel();
              panelQuickJump.setLayout( new GridBagLayout() );
             createQuickButtons();


         }

         void creatpanelMoviesArea()
         {
              panelMoviesArea = new JPanel();
              table = new JTable(20,4);

              panelMoviesArea.add(table);

         }
         void createpanelGenre()
         {
              list = new List();
              list.add("All");
              list.add("Action");
              list.add("Adventure");
              list.add("Animation");
              list.add("Comedy");
              list.add("Documentary");
              list.add("Drama");
              list.add("Horror");
              list.add("Sci-Fi");
              list.add("Suspense");
              list.add("Tv");


              panelGenre = new JPanel();
              panelGenre.add(list);


         }
         void createPanelToolBar()
         {
              panelToolbar = new JPanel();
              panelToolbar.setLayout( new GridBagLayout() );
              search_textfield = new JTextField( 10 );
              JLabel labelSearch = new JLabel("Search");
              panelToolbar.add(labelSearch, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(search_textfield, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_search, new GridBagConstraints( 2, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_addMovie, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_deleteMovie, new GridBagConstraints( 4, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_editMovie, new GridBagConstraints( 5, 0, 1, 1, 1.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
         }

         void createQuickButtons()
         {
              button_all = new JButton("all");
              button_all.addActionListener(this);
              panelQuickJump.add(button_all, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));

              //alphabet buttons
              for(int i=0; i < 26; i++)
              {
                   char string= 'a';
                   quickButtons[i] = new JButton("a");
                   quickButtons[i].addActionListener(this);
                   panelQuickJump.add(quickButtons[i], new GridBagConstraints( GridBagConstraints.RELATIVE, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              }

              //other buttons
              button_search = new JButton("Search");
              button_search.addActionListener(this);
             button_addMovie = new JButton("Add Movie");
             button_addMovie.addActionListener(this);
             button_deleteMovie = new JButton("Delete Movie");
             button_deleteMovie.addActionListener(this);
             button_editMovie = new JButton("Edit Movie");
             button_editMovie.addActionListener(this);
         }

         /**
        Performs the specific actions once a listener is invoked
        */
        public void actionPerformed(ActionEvent actionevent)
        {

        }



        public static void main(String args[])
        {
            TestLayout dogfiler = new TestLayout();

        }





    }
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 125 total points
Comment Utility
almost correctly arranged the controls here,

import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

import javax.swing.*;

    public class TestLayout extends JFrame implements ActionListener
    {
         JFrame frame;
         JPanel panelGenre;
         JPanel panelQuickJump;
         JPanel panelMoviesArea;
         JPanel panelToolbar;
         JPanel bottomPanel;


         List list;


         JTable table;


         JTextField search_textfield;


         //======Buttons=============
         JButton button_search;
         JButton button_addMovie;
         JButton button_deleteMovie;
         JButton button_editMovie;
         JButton button_all;
         JButton[] quickButtons = new JButton[26];


         JButton button_a;
         JButton button_b;
         JButton button_c;
         JButton button_d;
         JButton button_e;
         JButton button_f;
         JButton button_g;
         JButton button_h;
         JButton button_i;
         JButton button_j;
         JButton button_k;
         JButton button_l;
         JButton button_m;
         JButton button_n;
         JButton button_o;
         JButton button_p;
         JButton button_q;
         JButton button_r;
         JButton button_s;
         JButton button_t;
         JButton button_u;
         JButton button_v;
         JButton button_w;
         JButton button_x;
         JButton button_y;
         JButton button_z;

         JMenu file_menu;
         JMenuItem file_save;
         JMenuItem file_saveAs;
         JMenuItem file_exit;


         JMenu view_menu;

         JMenu help_menu;

         JMenuBar menuBar;


         TestLayout()
         {

              createGui();


         }


         void createGui()
         {
              frame = new JFrame("Movie Warehouse");

              createPanelQuickJump();
              createPanelToolBar();
              createMenuBar();
              createpanelGenre();
              creatpanelMoviesArea();

              //merge movies area and genre into one JPanel
              bottomPanel = new JPanel();
//              bottomPanel.add(panelGenre);
              bottomPanel.add(panelMoviesArea);

//              frame.getContentPane().setLayout(new GridLayout(3,1));
             JPanel pnlButton = new JPanel( new GridBagLayout() ) ;
             pnlButton.add( panelToolbar, new GridBagConstraints( 0, 0, 1, 1, 1.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0 ), 0, 0 ) ) ;
             pnlButton.add( panelQuickJump, new GridBagConstraints( 0, 1, 1, 1, 1.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0 ), 0, 0 ) ) ;
//             pnlButton.setPreferredSize( new Dimension( 600, 150 ) );
              //frame.getContentPane().add(menuBar);
             frame.getContentPane().add(pnlButton, BorderLayout.NORTH);
//              frame.getContentPane().add(panelQuickJump);
              frame.getContentPane().add( new JScrollPane( table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ) );
             frame.getContentPane().add( new JScrollPane( list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ), BorderLayout.WEST );
            frame.setLocationRelativeTo( null );         // Center the frame on the screen.
             frame.setSize( Toolkit.getDefaultToolkit().getScreenSize() );     //<============need to dynamicly set size!
             frame.setLocation( 0, 0 );
            frame.setVisible( true );
//            frame.pack();
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);

            // Make the frame visible to the user.              // Make the frame visible to the user.
              /*
              panelQuickJump;
              panelMoviesArea;
              panelToolbar;
              */



         }

         void createMenuBar()
         {
              //====File menu================
              file_menu = new JMenu("File");
              file_menu.add(file_save = new JMenuItem("Save"));
              file_menu.add(file_saveAs = new JMenuItem("Save As"));
              file_menu.add(file_exit = new JMenuItem("Exit"));


              //====View Menu================
              view_menu = new JMenu("View");

              //=Help Menu=================
              help_menu = new JMenu("Help");

              menuBar = new JMenuBar();

              menuBar.add(file_menu);
              menuBar.add(view_menu);
              menuBar.add(help_menu);
            frame.setJMenuBar(menuBar);


         }

         void createPanelQuickJump()
         {
              panelQuickJump = new JPanel();
              panelQuickJump.setLayout( new GridBagLayout() );
             createQuickButtons();


         }

         void creatpanelMoviesArea()
         {
              panelMoviesArea = new JPanel();
              table = new JTable(20,4);

              panelMoviesArea.add(table);

         }
         void createpanelGenre()
         {
              list = new List();
              list.add("All");
              list.add("Action");
              list.add("Adventure");
              list.add("Animation");
              list.add("Comedy");
              list.add("Documentary");
              list.add("Drama");
              list.add("Horror");
              list.add("Sci-Fi");
              list.add("Suspense");
              list.add("Tv");


              panelGenre = new JPanel();
              panelGenre.add(list);


         }
         void createPanelToolBar()
         {
              panelToolbar = new JPanel();
              panelToolbar.setLayout( new GridBagLayout() );
              search_textfield = new JTextField( 10 );
              JLabel labelSearch = new JLabel("Search");
              panelToolbar.add(labelSearch, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(search_textfield, new GridBagConstraints( 1, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_search, new GridBagConstraints( 2, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_addMovie, new GridBagConstraints( 3, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_deleteMovie, new GridBagConstraints( 4, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              panelToolbar.add(button_editMovie, new GridBagConstraints( 5, 0, 1, 1, 1.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
         }

         void createQuickButtons()
         {
              button_all = new JButton("all");
              button_all.addActionListener(this);
              panelQuickJump.add(button_all, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));

              //alphabet buttons
              for(int i=0; i < 26; i++)
              {
                   char string= 'a';
                   quickButtons[i] = new JButton("a");
                   quickButtons[i].addActionListener(this);
                   panelQuickJump.add(quickButtons[i], new GridBagConstraints( GridBagConstraints.RELATIVE, 0, 1, 1, 0.0, 0.0,
                 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              }

             panelQuickJump.add( new JLabel( "" ), new GridBagConstraints( GridBagConstraints.RELATIVE, 0, 1, 1, 1.0, 0.0,
           GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets( 0, 0, 0, 0 ), 0, 0 ));
              //other buttons
              button_search = new JButton("Search");
              button_search.addActionListener(this);
             button_addMovie = new JButton("Add Movie");
             button_addMovie.addActionListener(this);
             button_deleteMovie = new JButton("Delete Movie");
             button_deleteMovie.addActionListener(this);
             button_editMovie = new JButton("Edit Movie");
             button_editMovie.addActionListener(this);
         }

         /**
        Performs the specific actions once a listener is invoked
        */
        public void actionPerformed(ActionEvent actionevent)
        {

        }



        public static void main(String args[])
        {
            TestLayout dogfiler = new TestLayout();

        }





    }
0
 

Author Comment

by:tyweed420
Comment Utility
thanks for the code and actually laying it out!  

looks great!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

744 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

12 Experts available now in Live!

Get 1:1 Help Now