?
Solved

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

Posted on 2006-07-08
11
Medium Priority
?
485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17065600
Set a FlowLayout on each button panel
0
 
LVL 92

Expert Comment

by:objects
ID: 17066550
>           panelQuickJump.setLayout(new GridLayout(1,26));

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

Expert Comment

by:objects
ID: 17066551
same with your other button panels
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 86

Expert Comment

by:CEHJ
ID: 17066558
>>try commenting that line out.

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

Expert Comment

by:ksivananth
ID: 17069397
I would suggest combination of BorderLayout and GridBagLayout for your UI to get a better control!
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17069400
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
ID: 17078103
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
ID: 17078109
use GridBagLayout to setpreferredsize and setminimumsize to work!
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17078142
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 500 total points
ID: 17078201
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
ID: 17084348
thanks for the code and actually laying it out!  

looks great!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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 last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

777 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