BoxLayout vs GridBagLayout

Hi,
I heard that BoxLayout might be somehow deprecated or not recommended and whenever I have to layout a JPanel I should always prefer GridBagLayout - that's true? Why?

Oh Thanx, great flick!!
Where I'm from there's a saying a good horse jumps exactly as high as it needs to, well for me that's also a good rule for programming. But I know about the power and the issues you can have when working with GridbagLayout.
I started out and gave Gridbag a try but then I went back and caught experiences using other layout managers. But since I'm using a GUI builder, I rediscovered the Gridbag and now I think it's easy to handle when you work in combination with such a tool, without - it's a pain in the neck.
The resulting problem now for me was, working like that you really can do everything with Gridbag but it's also possible to avoid Gridbag completely using a mixture of the others. What I've heard is that Gridbag would be the future and the others would soon become obsolete - that's what I wondered.. am I the only guy who still works with other layout managers or are there others too, having the same probs. Now I think for my problem having a panel dynamically set up with elements in a BoxLayout (YAxis) style I'll use the Boxlayout and won't create a GridBag which behaves like Boxlayout.

Similar Messages

  • Maximum size of a JComboBox in a GridBagLayout

    I'm having a problem with a JComboBox inside a GridBagLayout. The general layout is a GridBag with labels / combo / textfields on the first line, a large table in a scrollpane that takes all columns on the second line, and a few labels / combo / textfields on the third.
    As long as the combo on the first combo is empty, it looks fine. When it gets populated, the combo gets resized to the size of the largest text. I would like to have it smaller and truncate the text.
    I tried to set maximum size, but the GridBag doesnt care. I've been trying with weightx but no success.
    What should I do ?

    And I would be interested which LayoutManager you prefer using.I don't use a single Layout Manager. I use a combination of Layout Managers to do the job. Thats why this question doesn't have a specific example. Remember LayoutManagers can be nested. The default layout manager for a frame is a border layout. That great for the general look of your application.
    a) you add a toolbar to the north
    b) you add a status bar to the south
    c) you add your main panel to the center.
    the main panel in turrn may use nested panels depending on your requirements. I don't do a lot of screen design but I typically use BorderLayout, FlowLayout, GridLayout and BoxLayout. GridBagLayout and SpringLayout have too many constraints to learn and master. They may be good for a GUI tool that only uses a single layout manager for the entire GUI, but I believe a better design is to break down the form into smaller more manageable areas and group components and use the appropriate layout manager for the group. That may or may not be a GridBagLayout for the small group, but I don't think you should force the entire form to use a GridbagLayout.

  • BoxLayout and Container.validate()

    I noticed that if a BoxLayout (or any other layout) is set for a Container, its explicit sizes (maximum and minimum) are ignored after validate() is called on that Container, meaning that the object is resized to values other than what it was configured with.
    Am I missing something? How do I prevent that from happening?
    thank you
    mike

    That matches our experience witth Box/BoxLayout.
    GridBagLayout has not such problem.

  • Minimize size of a JComboBox

    Hi,
    i�ve got a JComboBox rendered into a JTable. This works fine but the ComboBox is much to big. I played around with setMaximumSize in several LayoutManagers. The problem is that at a certain size it cuts the JComboBox. What to do? thanks
    uri

    And I would be interested which LayoutManager you prefer using.I don't use a single Layout Manager. I use a combination of Layout Managers to do the job. Thats why this question doesn't have a specific example. Remember LayoutManagers can be nested. The default layout manager for a frame is a border layout. That great for the general look of your application.
    a) you add a toolbar to the north
    b) you add a status bar to the south
    c) you add your main panel to the center.
    the main panel in turrn may use nested panels depending on your requirements. I don't do a lot of screen design but I typically use BorderLayout, FlowLayout, GridLayout and BoxLayout. GridBagLayout and SpringLayout have too many constraints to learn and master. They may be good for a GUI tool that only uses a single layout manager for the entire GUI, but I believe a better design is to break down the form into smaller more manageable areas and group components and use the appropriate layout manager for the group. That may or may not be a GridBagLayout for the small group, but I don't think you should force the entire form to use a GridbagLayout.

  • How can I display JTextFields correctly on a JPanel using GridBagLayout?

    I had some inputfields on a JPanel using the boxLayout. All was ok. Then I decided to change the panellayout to GridBagLayout. The JLabel fields are displayed correctly but the JTextField aren't. They are at the JPanel but have a size of 0??? So we cannot see what we type in these fields... Even when I put some text in the field before putting it on the panel.
    How can I display JTextFields correctly on a JPanel using GridBagLayout?
    here is a shortcut of my code:
    private Dimension sFieldSize10 = new Dimension(80, 20);
    // Create and instantiate Selection Fields
    private JLabel lSearchAbrText = new JLabel();
    private JTextField searchAbrText = new JTextField();
    // Set properties for SelectionFields
    lSearchAbrNumber.setText("ABR Number (0-9999999):");
    searchAbrNumber.setText("");
    searchAbrNumber.createToolTip();
    searchAbrNumber.setToolTipText("enter the AbrNumber.");
    searchAbrNumber.setPreferredSize(sFieldSize10);
    searchAbrNumber.setMaximumSize(sFieldSize10);
    public void createViewSubsetPanel() {
    pSubset = new JPanel();
    // Set layout
    pSubset.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    // Add Fields
    gbc.gridy = 0;
    gbc.gridx = GridBagConstraints.RELATIVE;
    pSubset.add(lSearchAbrNumber, gbc);
    // also tried inserting this statement
    // searchAbrNumber.setText("0000000");
    // without success
    pSubset.add(searchAbrNumber,gbc);
    pSubset.add(lSearchAbrText, gbc);
    pSubset.add(searchAbrText, gbc);
    gbc.gridy = 1;
    pSubset.add(lSearchClassCode, gbc);
    pSubset.add(searchClassCode, gbc);
    pSubset.add(butSearch, gbc);
    }

    import java.awt.*;
    import java.awt.event.*;
    import javax .swing.*;
    public class GridBagDemo {
      public static void main(String[] args) {
        JLabel
          labelOne   = new JLabel("Label One"),
          labelTwo   = new JLabel("Label Two"),
          labelThree = new JLabel("Label Three"),
          labelFour  = new JLabel("Label Four");
        JLabel[] labels = {
          labelOne, labelTwo, labelThree, labelFour
        JTextField
          tfOne   = new JTextField(),
          tfTwo   = new JTextField(),
          tfThree = new JTextField(),
          tfFour  = new JTextField();
        JTextField[] fields = {
          tfOne, tfTwo, tfThree, tfFour
        Dimension
          labelSize = new Dimension(125,20),
          fieldSize = new Dimension(150,20);
        for(int i = 0; i < labels.length; i++) {
          labels.setPreferredSize(labelSize);
    labels[i].setHorizontalAlignment(JLabel.RIGHT);
    fields[i].setPreferredSize(fieldSize);
    GridBagLayout gridbag = new GridBagLayout();
    JPanel panel = new JPanel(gridbag);
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.insets = new Insets(5,5,5,5);
    panel.add(labelOne, gbc);
    panel.add(tfOne, gbc);
    gbc.gridwidth = gbc.RELATIVE;
    panel.add(labelTwo, gbc);
    gbc.gridwidth = gbc.REMAINDER;
    panel.add(tfTwo, gbc);
    gbc.gridwidth = 1;
    panel.add(labelThree, gbc);
    panel.add(tfThree, gbc);
    gbc.gridwidth = gbc.RELATIVE;
    panel.add(labelFour, gbc);
    gbc.gridwidth = gbc.REMAINDER;
    panel.add(tfFour, gbc);
    final JButton
    smallerButton = new JButton("smaller"),
    biggerButton = new JButton("wider");
    final JFrame f = new JFrame();
    ActionListener l = new ActionListener() {
    final int DELTA_X = 25;
    int oldWidth, newWidth;
    public void actionPerformed(ActionEvent e) {
    JButton button = (JButton)e.getSource();
    oldWidth = f.getSize().width;
    if(button == smallerButton)
    newWidth = oldWidth - DELTA_X;
    if(button == biggerButton)
    newWidth = oldWidth + DELTA_X;
    f.setSize(new Dimension(newWidth, f.getSize().height));
    f.validate();
    smallerButton.addActionListener(l);
    biggerButton.addActionListener(l);
    JPanel southPanel = new JPanel(gridbag);
    gbc.gridwidth = gbc.RELATIVE;
    southPanel.add(smallerButton, gbc);
    gbc.gridwidth = gbc.REMAINDER;
    southPanel.add(biggerButton, gbc);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(panel);
    f.getContentPane().add(southPanel, "South");
    f.pack();
    f.setLocation(200,200);
    f.setVisible(true);

  • Problem with the GridBagLayout Manager

    Hello i am new to Java Swing and i am facing a problem with the GridBagLayout layout manager . the code in question is attached. First compile and run the code. It will execute w/o probs . Then go to the "Console" tab. There the diff components (6 buttons and 1 text area) are haphazardly arranged where as all measures where taken to prevent it in the code. The GridBagLayout manager for this tab is not working properly please help.
    The code in question:-
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class MainForm extends JFrame{
         JTabbedPane jtp = new JTabbedPane();
         Container generalContainer; // container for the general pane
         Container consoleContainer; // container for the console pane
         GridBagLayout consoleLayout = new GridBagLayout(); // GridBagLayout for the console
         GridBagConstraints consoleConstraints;// GridBagConstraints for the console
         public MainForm()
              super("Welcome to Grey Griffin -- Network Simulator");
              setSize(700,600);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              JPanel generalPane = new JPanel();
              generalPane.setLayout(new BoxLayout(generalPane, BoxLayout.Y_AXIS));
              JPanel consolePane = new JPanel();
              consolePane.setLayout(new BoxLayout(consolePane, BoxLayout.Y_AXIS));
              JPanel designPane = new JPanel();
              designPane.setLayout(new BoxLayout(designPane, BoxLayout.Y_AXIS));
              JPanel outputPane = new JPanel();
              outputPane.setLayout(new BoxLayout(outputPane, BoxLayout.Y_AXIS));
              //Setting up Layout for all the tabs
               //for general tab
               FlowLayout layout= new FlowLayout();
               generalContainer = generalPane;
               layout.setAlignment(FlowLayout.CENTER);
               generalContainer.setLayout( layout );
               //for  console tab
               consoleContainer = consolePane;
               consoleConstraints = new GridBagConstraints();
               // *******Finished********
              //********** All buttons text areas are declared here**********
                //*******for the general tab**********
              JButton generalCreate = new JButton("Create a New Network");
              JButton generalOpen = new JButton("Open an Existing Network");
              JButton generalSave = new JButton("Save the Network");
              JButton generalSaveAs = new JButton("Save As..........");
              JButton generalExit = new JButton("Exit");
              //******END******
             //*******for the console tab
                 //text area          
              JTextArea consoleCode = new JTextArea();
              consoleCode.setEditable(true);
              consoleCode.setMaximumSize(new Dimension(700,400));
              consoleCode.setAlignmentX(0.0f);
                   //text area complete
                 //*******for the Console tab**********
              JButton consoleCompile = new JButton("Compile Code");
              JButton consoleSimulate = new JButton("Simulate Code");
              JButton consoleReset = new JButton("Reset");
              JButton consoleOpen = new JButton("Open script files");
              JButton consoleSave = new JButton("Save script files");
              JButton consoleConvert = new JButton("Convert Script files to graphical form");
              //***************END****************
         //Adding buttons and text areas to there respective tabs
              // for the general tab
              generalContainer.add(generalCreate);
              generalContainer.add(generalOpen);
              generalContainer.add(generalSave);
              generalContainer.add(generalSaveAs);
             generalContainer.add(generalExit);
             //****END****
              // for the console tab          
              consoleConstraints.fill = GridBagConstraints.BOTH;
              addComp(consoleOpen,0,0,1,1);
              consoleConstraints.fill = GridBagConstraints.BOTH;
              addComp(consoleSave,1,1,1,1);
              consoleConstraints.fill = GridBagConstraints.BOTH;
              addComp(consoleConvert,1,2,1,1);
              consoleConstraints.fill = GridBagConstraints.BOTH;
              addComp(consoleCode,1,0,3,1);
              consoleConstraints.fill = GridBagConstraints.BOTH;
              addComp(consoleCompile,2,0,1,1);
              consoleConstraints.fill = GridBagConstraints.BOTH;
              addComp(consoleSimulate,2,1,1,1);
              consoleConstraints.fill = GridBagConstraints.BOTH;
              addComp(consoleReset,2,2,1,1);
              //****END****
              // adding the tabs
              jtp.addTab("General",null,generalPane,"Choose General Options");
              jtp.addTab("Design",null,designPane,"Design your own network!!");
              jtp.addTab("Console",null,consolePane,"Type commands in console for designing");
              jtp.addTab("Output",null,outputPane,"View output");
              getContentPane().add(jtp, BorderLayout.CENTER);
              //****END****
         //This method is used to ad the buttons in the GridBagLayout of the Console tab
         private void addComp( Component c,int row,int column,int width,int height)
            // set gridx and gridy
            consoleConstraints.gridx=column;
            consoleConstraints.gridy=row;
            //set gridwidth and grid height
            consoleConstraints.gridwidth=width;
            consoleConstraints.gridheight=height;
            //set constraints
            consoleLayout.setConstraints(c,consoleConstraints);
            consoleContainer.add(c);     
         class TabManager implements ItemListener
              Component tab;
              public TabManager(Component tabToManage)
                   tab = tabToManage;
         public void itemStateChanged(ItemEvent ie)
              int index=jtp.indexOfComponent(tab);
             if (index!=-1)
                  jtp.setEnabledAt(index,ie.getStateChange()== ItemEvent.SELECTED);
             MainForm.this.repaint();
    public static void main(String args[])
         MainForm form = new MainForm();
         form.setVisible(true);
    }

    Thanks for the suggestions. I did away with the GridBagLayout Altogether :-D
    and put all the buttons in a seperate JPanel and added that JPanel into the Console tabs container which was using a BorderLayout this time. Take a look
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class MainForm extends JFrame{
         JTabbedPane jtp = new JTabbedPane();
         public MainForm()
              super("Welcome to Grey Griffin -- Network Simulator");
              setSize(800,600);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              JPanel generalPane = new JPanel();
              generalPane.setLayout(new BoxLayout(generalPane, BoxLayout.Y_AXIS));
              JPanel consolePane = new JPanel();
              consolePane.setLayout(new BoxLayout(consolePane, BoxLayout.Y_AXIS));
              JPanel designPane = new JPanel();
              designPane.setLayout(new BoxLayout(designPane, BoxLayout.Y_AXIS));
              JPanel outputPane = new JPanel();
              outputPane.setLayout(new BoxLayout(outputPane, BoxLayout.Y_AXIS));
              //Setting up Layout for all the tabs
              //**for the general tab
               Container generalContainer;
               FlowLayout layoutGeneral= new FlowLayout();
               generalContainer = generalPane;
               layoutGeneral.setAlignment(FlowLayout.CENTER);
               generalContainer.setLayout( layoutGeneral );
               //**for the console tab
                Container consoleContainer;
                consoleContainer = consolePane;
                consoleContainer.setLayout(new BorderLayout() );
               //Creating buttonpanel for adding the buttons
                JPanel buttonPanel1 = new JPanel();
                buttonPanel1.setLayout(new GridLayout(1,3));
                JPanel buttonPanel2 = new JPanel();
                buttonPanel2.setLayout(new GridLayout(1,3));
              // All buttons / text areas / images are declared here
              //**Buttons for the general tab**//
              JButton generalCreate = new JButton("Create a New Network");
              JButton generalOpen = new JButton("Open an Existing Network");
              JButton generalSave = new JButton("Save the Network");
              JButton generalSaveAs = new JButton("Save As..........");
              JButton generalExit = new JButton("Exit");
              //declaring the buttons
              JButton consoleCompile = new JButton("Compile");
              JButton consoleRun = new JButton("Run");
              JButton consoleReset = new JButton("Reset");
              JButton consoleOpen = new JButton("Open script files");
              JButton consoleSave = new JButton("Save script files");
              JButton consoleConvert = new JButton("Convert Script files to graphical form");
              //declares the textarea where the code is written
              JTextArea consoleCode = new JTextArea();
              consoleCode.setEditable(true);
              consoleCode.setMaximumSize(new Dimension(500,600));
              consoleCode.setAlignmentX(0.0f);
              //Adding buttons and text areas to there respective tabs     
              //**Buttons and text pads for the general tab**
                   generalContainer.add(generalCreate);
              generalContainer.add(generalOpen);
              generalContainer.add(generalSave);
              generalContainer.add(generalSaveAs);
                 generalContainer.add(generalExit);
              //adding buttons to the button panel 1
              buttonPanel1.add(consoleOpen);
              buttonPanel1.add(consoleSave);
              buttonPanel1.add(consoleConvert);
              //adding buttons to the button panel2          
              buttonPanel2.add(consoleRun);
              buttonPanel2.add(consoleReset);
              buttonPanel2.add(consoleCompile);
              //adding button panels and textarea
              consoleContainer.add(buttonPanel1,BorderLayout.NORTH);
              consoleContainer.add(consoleCode,BorderLayout.CENTER);
              consoleContainer.add(new JScrollPane(consoleCode));
              consoleContainer.add(buttonPanel2,BorderLayout.SOUTH);
              //adding the tabs          
              jtp.addTab("General",null,generalPane,"Choose General Options");
              jtp.addTab("Design",null,designPane,"Design your own network!!");
              jtp.addTab("Console",null,consolePane,"Type commands in console for designing");
              jtp.addTab("Output",null,outputPane,"View output");
              getContentPane().add(jtp, BorderLayout.CENTER);
         class TabManager implements ItemListener
              Component tab;
              public TabManager(Component tabToManage)
                   tab = tabToManage;
         public void itemStateChanged(ItemEvent ie)
              int index=jtp.indexOfComponent(tab);
             if (index!=-1)
                  jtp.setEnabledAt(index,ie.getStateChange()== ItemEvent.SELECTED);
             MainForm.this.repaint();
    public static void main(String args[])
         MainForm form = new MainForm();
         form.setVisible(true);
    }

  • BoxLayout & Borders

    Hi !
    I'm trying to add a JPanel to a panel using BoxLayout. When I set a border to the subPanel, it deasapear ! Here is the code :
    // Inside a class extending JPanel
         private void initComponents()
              setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
              setBorder(BorderFactory.createEtchedBorder());
              mandatoryPanel = new JPanel(new SpringLayout());
              initMandatoryPanelComponents();
              mandatoryPanel.setPreferredSize(new Dimension(700, 150));
              mandatoryPanel.setMinimumSize(new Dimension(700, 150));
              mandatoryPanel.setBorder(BorderFactory.createEtchedBorder());
              add(mandatoryPanel);
         }When I comment the line where border is set, the panel is displayed correctly. Else, nothing is displayed.
    Can anyone help me ?

    In my tests I got the following results using the following code:
                   //jPanel1 = new JPanel();
                   jPanel1 = new JPanel(new SpringLayout());
                   //jPanel1.setLayout(new GridBagLayout());
                   jPanel1.setBorder(BorderFactory.createEtchedBorder());
                   jPanel1.add(getJButton1(), new GridBagConstraints());
                   jContentPane.add(jPanel1, null);If I use a GridBagLayout, everything seems fine. However, if I use the SpringLayout the etchedBorder causes problems. It seems that the two are mutally exclusive in some way that I don't know about.

  • JButton in a BoxLayout

    A JButton has not the same reaction like a JTextField in a BoxLayout.
    Why? I need something like this and don't know how:
    JLabel JButton
    JLabel JButton
    The JButtons don't have the same Text, but they must have the same size and the same Difference from the JLabel.
    Please send me an E-Mail:
    [email protected]
    Thanks!!!

    You want a 2x2 arrangement? That's not what BoxLayout does: "A layout manager that allows multiple components to be laid out either vertically or horizontally."
    Try a GridLayout and set the number of Rows/Cols. "The container is divided into equal-sized rectangles, and one component is placed in each rectangle." This results in equal size for all - JLabel same size as JButton.
    If this doesn't meet your needs, then there's GridBagLayout, which is real easy to setup if you have a WYSIWYG GUI editor, like Forte.
    Remember, you're encouraged to group stuff in JPanels to makes things easier. For instance, you might create 2 JPanels - one for JLabels and one for JButtons - give each one a GridLayout (col=1,rows=#rows) so all JLabels are same size and all JButtons are same size. Put the 2 JPanels side-by-side with a FlowLayout and you're golden.

  • Another GridBagLayout question

    I still don't get it. Why is it that the weightx is not working properly? The proportion between the label and textfield is greater than the insets I have specified which is 5. Could someone help please.
    JLabel l;
    JComponent comp;             
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    comp = new JPanel(new GridBagLayout());
    comp.setBorder(BorderFactory.createTitledBorder(""));
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.NONE;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = .1;
    l = new JLabel("ID", JLabel.LEFT);  // This lines up correctly
    comp.add(l, gbc);
    gbc.gridx++;
    gbc.weightx = .9;
    supplierID = new JTextField(5); // This is too far from the label
    comp.add(supplierID, gbc);
    gbc.gridx = 0;
    gbc.gridy++;
    l = new JLabel("Supplier", JLabel.LEFT);
    comp.add(l, gbc);
    gbc.gridx++;
    supplierName = new JTextField("supplier name", 30);             
    comp.add(supplierName, gbc);          
    panel.add(comp);
    comp = new JPanel(new GridBagLayout());
    comp.setBorder(BorderFactory.createTitledBorder("Address"));
    gbc.gridx = 0;
    gbc.gridy = 0;
    l = new JLabel("Mail Addr", JLabel.LEFT);
    comp.add(l, gbc);
    gbc.gridx++;
    supplierAddress1 = new JTextField(20);
    comp.add(supplierAddress1, gbc);
    gbc.gridx++;
    l = new JLabel("Ship Addr", JLabel.LEFT);
    comp.add(l, gbc);
    gbc.gridx++;
    supplierAddress2 = new JTextField(20);
    comp.add(supplierAddress2, gbc);             
    panel.add(comp);            
    return panel;

    Hi allenvpn,
    The weights are used to figure out where to add the extra space to. When dealing with labels you should have their weights set to zero because there is no need to expand them.
    You just have to make the weightx zero for your labels: (ID, Supplier) and make the weightx one for your textfields.
    gbc.weigthx = 0;
    l = new JLabel("ID", JLabel.LEFT); // This lines up correctly
    comp.add(l, gbc);
    gbc.weightx = 1;
    supplierName = new JTextField("supplier name", 30);      
    comp.add(supplierName, gbc);
    gbc.weightx = 0;
    l = new JLabel("Supplier", JLabel.LEFT);
    comp.add(l, gbc);
    gbc.weightx = 1;
    supplierName = new JTextField("supplier name", 30);      
    comp.add(supplierName, gbc);
    This will allow your textfields to align on the left side just beyond the longest label.
    Regards,
    Manfred.

  • Creating filling panel with insets without gridbaglayout

    Hi,
    This is quite a newbie prob but i can't seem to get it right. I want a Panel with two panels. Both with insets. I want the first to only fill horizontally. The second has to fill-up the rest of the panel. Because Boxlayout and Borderlayout don't support insets with layout i tried the gridbaglayout, but i can't get the second panel to fill the remainder of the panel. It stops halfway.
    contentPane.add(one,
    new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
    new Insets(2, 2, 2, 2), 0, 0));
    contentPane.add(two,
    new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
    GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0));
    Can anyone tell me how to do this?
    Much thanks
    Hugo Hendriks

    You can use:
    panel.setBorder(BorderFactory.createEmptyborder(2,2,2,2));
    to set insets on a JPanel. I believe Insets is the "old" way of doing borders.
    Regards,
    Tim

  • GridBagLayout always starts in center

    Hi,
    I'm programming a Application here which is a JFrame, that has a JTabbedPane "inside". All tabs add classes that are extenden from JPanel. Those classes using GridBagLayout.
    My Problem is, that all Components inside the JPanel are starting in the absolute Center of the Tab.
    The JFrame uses BorderLayout and the from JPanel extended classes using the GridBagLayout.
    What is wrong?
    Thank you very much for all your help :)
    LoCal

    Yes, GridBagLayout stinks in a lot of ways.
    But, what you want to do is to wrap the panel
    (govered by the GridBagLayout) inside another
    panel which is goverened by a BoxLayout.
    Lock the outer panel to its preferred size
    (which will be its content's preferred size.
    THEN, you can place the outer panel
    (the one governed by the BoxLayout) into the
    frame using desired alignments (top, left, etc.)
    You see, the problem you are having is that
    panels governed by GridBagLayout always will
    expand to fill the size of their containers,
    even if you try and lock them to their preferred
    sizes. BoxLayout, on the other hand, will
    respect the size you set it to., and will not
    expand to fill its container. This allows
    you to then do things like align it and it will
    obey.
    You'll need to use the methods get/setSize(),
    get/setMaximumSize(), get/setMinimumSize(),
    and getPreferredSize(). May need to call all
    of the set methods. I've had most luck with
    specifying all of them.
    b.c

  • GridBagLayout Issues

    Hello All.
    I'm having problems with this panel. I added a new instance of the
    panel to three different Custom JDialogs that also contain another panel.
    I have tested this panel in a JFrame, and it works there. However, in
    my custom JDialogs, it seems like all of the componenets are rendered
    to two differenet places at the same time and the components 'flicker'.
    Also, the commented setLayout call ( BoxLayout) does not cause any
    problem. Is there anything that I am missing here that someone
    can help me with?
    public static class ChromSelectionPanel extends JPanel implements
                   ActionListener {
              private JList chromList;
              private JCheckBox selectAllCB;
              private JScrollPane scrollPane;
              private GridBagConstraints c = new GridBagConstraints();
              public ChromSelectionPanel(Dimension size) {
                   super();
                   this.setSize(size);
                   this.setBorder(BorderFactory
                             .createTitledBorder("Chromosome Selection:"));
                   this.setLayout(new GridBagLayout());
                   //this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
                   c.insets = new Insets(2, 2, 2, 2);
                   c.fill = GridBagConstraints.BOTH;
                   selectAllCB = new JCheckBox("Select All");
                   selectAllCB.addActionListener(this);
                   c.gridx = 0;
                   c.gridy = 0;
                   c.anchor = GridBagConstraints.LINE_END;
                   this.add(selectAllCB, c);
                   JLabel or = new JLabel(" Or ");
                   c.gridx = 1;
                   c.gridy = 0;
                   c.anchor = GridBagConstraints.LINE_START;
                   this.add(or, c);
                   String[] chromOptions = { "1", "2", "3", "4", "5", "6", "7", "8",
                             "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
                             "19", "20", "21", "22", "X", "Y" };
                   chromList = new JList(chromOptions);
                   chromList.setSize(10, 10);
                   scrollPane = new JScrollPane(chromList);
                   scrollPane.setSize(new Dimension(50, 50));
                   JPanel scrollPaneHolder = new JPanel();
                   scrollPaneHolder.add(scrollPane);
                   c.gridx = 2;
                   c.anchor = GridBagConstraints.LINE_START;
                   this.add(scrollPaneHolder, c);
                   JLabel tutorialLabel = new JLabel(
                             "<html><i>Use the SHIFT key to select multiple <br>"
                                       + " entries.  Use the CTRL key to toggle <br> selections on and off.</i></html>");
                   c.gridx = 3;
                   this.add(tutorialLabel, c);
              public List<Integer> getSelectedChroms() {
                   ArrayList<Integer> list = null;
                   if (selectAllCB.isSelected()) {
                        list = new ArrayList<Integer>(24);
                        for (int i = 1; i < 25; i++) {
                             list.add(new Integer(i));
                   } else {
                        for (Object o : chromList.getSelectedValues()) {
                             if (!o.toString().equalsIgnoreCase("X")
                                       && !o.toString().equalsIgnoreCase("Y"))
                                  list.add(Integer.parseInt(o.toString()));
                             else if (o.toString().equalsIgnoreCase("x"))
                                  list.add(new Integer(23));
                             else
                                  list.add(new Integer(24));
                   return list;
              public void actionPerformed(ActionEvent e) {
                   System.out.println(e.getSource().toString());
                   System.out.println();
                   if (e.getSource() == selectAllCB) {
                        if (selectAllCB.isSelected()) {
                             chromList.setEnabled(false);
                             scrollPane.setEnabled(false);
                             scrollPane.getVerticalScrollBar().setEnabled(false);
                        } else {
                             System.out.println("Not selected");
                             chromList.setEnabled(true);
                             scrollPane.setEnabled(true);
                             scrollPane.getVerticalScrollBar().setEnabled(true);
         }Thanks for any insights, comments, help
    d

    hmm... still can't figure out what was causing the problem so I ended up
    just switching to BoxLayout with some extra panels to get the
    posistioning correct
    d

  • GridBagLayout and Panel Border problem

    I have 3 panels like
    A
    B
    C
    and the C panel has a Mouse Listener that on a mouseEntered creates a border around the same panel and on a mouseExited clears that border.
    When this border is created the A and B panels go up a little bit .. they move alone when the border is created.
    Is there any way to fix this problem? Is there any way to get the panels static?
    the code is close to the following:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    import javax.swing.BorderFactory;
    import javax.swing.border.Border;
    import javax.swing.border.TitledBorder;
    import java.awt.event.*;
    import java.text.NumberFormat;
    public class Game extends JFrame implements MouseListener
    JPanel game, options, top, down, middle;
    NumberFormat nf;
    public Game() {
    super("Game");
    nf = NumberFormat.getPercentInstance();
    nf.setMaximumFractionDigits(1);
    JPanel center = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = gbc.BOTH;
    gbc.weighty = 1.0;
    gbc.weightx = 0.8;
    center.add(getGamePanel(), gbc);
    gbc.weightx = 0.104;
    center.add(getOptionsPanel(), gbc);
    Container cp = getContentPane();
    // use the JFrame default BorderLayout
    cp.add(center); // default center section
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setSize(700,600);
    // this.setResizable(false);
    setLocationRelativeTo(null);
    setVisible(true);
    addComponentListener(new ComponentAdapter()
    public void componentResized(ComponentEvent e)
    showSizeInfo();
    showSizeInfo();
    private void showSizeInfo()
    Dimension d = getContentPane().getSize();
    double totalWidth = game.getWidth() + options.getWidth();
    double gamePercent = game.getWidth() / totalWidth;
    double optionsPercent = options.getWidth() / totalWidth;
    double totalHeight = top.getHeight() + middle.getHeight() + down.getHeight();
    double topPercent = top.getHeight() / totalHeight;
    double middlePercent = middle.getHeight() / totalHeight;
    double downPercent = down.getHeight() / totalHeight;
    System.out.println("content size = " + d.width + ", " + d.height + "\n" +
    "game width = " + nf.format(gamePercent) + "\n" +
    "options width = " + nf.format(optionsPercent) + "\n" +
    "top height = " + nf.format(topPercent) + "\n" +
    "middle height = " + nf.format(middlePercent) + "\n" +
    "down height = " + nf.format(downPercent) + "\n");
    private JPanel getGamePanel()
    // init components
    top = new JPanel(new BorderLayout());
    top.setBackground(Color.red);
    top.add(new JLabel("top panel", JLabel.CENTER));
    middle = new JPanel(new BorderLayout());
    middle.setBackground(Color.green.darker());
    middle.add(new JLabel("middle panel", JLabel.CENTER));
    down = new JPanel(new BorderLayout());
    down.setBackground(Color.blue);
    down.add(new JLabel("down panel", JLabel.CENTER));
    // layout game panel
    game = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.fill = gbc.BOTH;
    gbc.gridwidth = gbc.REMAINDER;
    gbc.weighty = 0.2;
    game.add(top, gbc);
    gbc.weighty = 0.425;
    game.add(middle, gbc);
    gbc.weighty = 0.2;
    game.add(down, gbc);
    down.addMouseListener(this);
    return game;
    private JPanel getOptionsPanel()
    options = new JPanel(new BorderLayout());
    options.setBackground(Color.pink);
    options.add(new JLabel("options panel", JLabel.CENTER));
    return options;
    // mouse listener events
         public void mouseClicked( MouseEvent e ) {
    System.out.println("pressed");
         public void mousePressed( MouseEvent e ) {
         public void mouseReleased( MouseEvent e ) {
         public void mouseEntered( MouseEvent e ) {
    Border redline = BorderFactory.createLineBorder(Color.red);
    JPanel x = (JPanel) e.getSource();
    x.setBorder(redline);
         public void mouseExited( MouseEvent e ){
    JPanel x = (JPanel) e.getSource();
    x.setBorder(null);
    public static void main(String[] args ) {
    Game exe = new Game();
    exe.show();
    }

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.text.NumberFormat;
    public class Game extends JFrame implements MouseListener{
      JPanel game, options, top, down, middle;
      NumberFormat nf;
      public Game() {
        super("Game");
        nf = NumberFormat.getPercentInstance();
        nf.setMaximumFractionDigits(1);
        JPanel center = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = gbc.BOTH;
        gbc.weighty = 1.0;
        gbc.weightx = 0.8;
        center.add(getGamePanel(), gbc);
        gbc.weightx = 0.104;
        center.add(getOptionsPanel(), gbc);
        Container cp = getContentPane();
        // use the JFrame default BorderLayout
        cp.add(center); // default center section
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(700,600);
        // this.setResizable(false);
        setLocationRelativeTo(null);
        setVisible(true);
        addComponentListener(new ComponentAdapter(){
            public void componentResized(ComponentEvent e){
            showSizeInfo();
        showSizeInfo();
      private void showSizeInfo(){
        Dimension d = getContentPane().getSize();
        double totalWidth = game.getWidth() + options.getWidth();
        double gamePercent = game.getWidth() / totalWidth;
        double optionsPercent = options.getWidth() / totalWidth;
        double totalHeight = top.getHeight() + middle.getHeight() + down.getHeight();
        double topPercent = top.getHeight() / totalHeight;
        double middlePercent = middle.getHeight() / totalHeight;
        double downPercent = down.getHeight() / totalHeight;
        System.out.println("content size = " + d.width + ", " + d.height + "\n" +
            "game width = " + nf.format(gamePercent) + "\n" +
            "options width = " + nf.format(optionsPercent) + "\n" +
            "top height = " + nf.format(topPercent) + "\n" +
            "middle height = " + nf.format(middlePercent) + "\n" +
            "down height = " + nf.format(downPercent) + "\n");
      private JPanel getGamePanel(){
        // init components
        top = new JPanel(new BorderLayout());
        top.setBackground(Color.red);
        top.add(new JLabel("top panel", JLabel.CENTER));
        middle = new JPanel(new BorderLayout());
        middle.setBackground(Color.green.darker());
        middle.add(new JLabel("middle panel", JLabel.CENTER));
        down = new JPanel(new BorderLayout());
        down.setBackground(Color.blue);
        down.add(new JLabel("down panel", JLabel.CENTER));
        // layout game panel
        game = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.fill = gbc.BOTH;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.weighty = 0.2;
        game.add(top, gbc);
        gbc.weighty = 0.425;
        game.add(middle, gbc);
        gbc.weighty = 0.2;
        game.add(down, gbc);
        down.addMouseListener(this);
        return game;
      private JPanel getOptionsPanel(){
        options = new JPanel(new BorderLayout());
        options.setBackground(Color.pink);
        options.add(new JLabel("options panel", JLabel.CENTER));
        return options;
      public void mouseClicked( MouseEvent e ) {
        System.out.println("pressed");
      public void mousePressed( MouseEvent e ) {
      public void mouseReleased( MouseEvent e ) {
      public void mouseEntered( MouseEvent e ) {
        Border redline = new CalmLineBorder(Color.red);
        JPanel x = (JPanel) e.getSource();
        x.setBorder(redline);
      public void mouseExited( MouseEvent e ){
        JPanel x = (JPanel) e.getSource();
        x.setBorder(null);
      public static void main(String[] args ) {
        Game exe = new Game();
        exe.setVisible(true);
    class CalmLineBorder extends LineBorder{
      public CalmLineBorder(Color c){
        super(c);
      public CalmLineBorder(Color c, int thick){
        super(c, thick);
      public CalmLineBorder(Color c, int thick, boolean round){
        super(c, thick, round);
      public Insets getBorderInsets(Component comp){
        return new Insets(0, 0, 0, 0);
    }

  • GridBagLayout Problem

    I have a jframe in which i want to display 2 jpanels (panelA, panelB).
    The arrangement for panelA is at cell (1,1) and for panelB at cell(1,3)
    cell(0,0) upper-left
    Here is my code:
    GridBagLayout gridBag = new GridBagLayout();
    GridBagConstraints constr = new GridBagConstraints();
    mainFrame = new JFrame("MAIN-FRAME");
    mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
    aDesktopPane = new JDesktopPane();
    aDesktopPane.setBackground(Color.LIGHT_GRAY);
    aDesktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    mainFrame.setContentPane(aDesktopPane);
    mainFrame.getContentPane().setLayout(gridBag);
    BuildConstraints(constr,0,1,1,1,30,0);
    constr.fill=GridBagConstraints.BOTH;
    constr.insets = createFeatures.Inset(3,3,3,3);
    JPanel justForLayout = new JPanel(gridBag); //i use this panel for helping me at the arrangment
    justForLayout.setBackground(Color.LIGHT_GRAY);
    mainFrame.getContentPane().add(justForLayout,constr);
    BuildConstraints(constr,1,1,1,1,40,70);
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.insets = createFeatures.Inset(3,3,3,3);
    mainFrame.getContentPane().add(panelA, constr);
    BuildConstraints(constr,2,1,1,1,30,0);
    constr.fill=GridBagConstraints.BOTH;
    constr.insets = createFeatures.Inset(3,3,3,3);
    JPanel justForLayout2 = new JPanel(gridBag);//i use this panel for helping me at the arrangment
    justForLayout2.setBackground(Color.LIGHT_GRAY);
    mainFrame.getContentPane().add(justForLayout2,constr);
    BuildConstraints(constr,1,3,1,1,0,30);
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.insets = createFeatures.Inset(3,3,3,3);
    mainFrame.getContentPane().add(panelB, constr);
    public void BuildConstraints (GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) {
         gbc.gridx = gx;
         gbc.gridy = gy;
         gbc.gridwidth = gw;
         gbc.gridheight = gh;
         gbc.weightx = wx;
         gbc.weighty = wy;
    }//end method Buildconstrraints()

    Try this as a demo, you may have to work with it a bit.
           JPanel mainPanel = (JPanel) getContentPane();
            mainPanel.setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            JPanel PanelA = new JPanel();
            PanelA.setBorder(BorderFactory.createEtchedBorder());
            PanelA.add(new JLabel("I'm panel A"));
            JPanel PanelB = new JPanel();
            PanelB.setBorder(BorderFactory.createEtchedBorder());
            PanelB.add(new JLabel("I'm Panel B"));
            gbc.anchor = GridBagConstraints.WEST;
            gbc.fill = GridBagConstraints.BOTH;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.insets = new Insets(40, 10, 40, 10);    //top,left,bottom,right
            mainPanel.add(PanelA, gbc);
            mainPanel.add(PanelB, gbc);

  • Problem with gridbaglayout in JPanel

    Hello I am trying to display contact information in three serperate Jpanels on tabbbed panes.I would like to get help in configuring maybe just the pane of void showPane1().I need something like
    Searchlb | Combodropname1
    firstnamelb | firstnametxt | lastnamelb | lastnametxt
    Addresslb addresslb.Horizontal-----------------------*-
    citylb | citytxt | statelb | statetxt
    postcodelb | postcodetxt | countrylb | countrytxt
    emaillb | emailtxt | homephonelb | homephonetxt
    faxnumberlb | faxnumbertxt
    Other panes have buttons
    Here`s the code it operates on login of MSAccess table called persons:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    import java.io.*;
    import java.util.Date;
    import java.text.NumberFormat;
    public class Addressbook extends JFrame{
         // Define constant variables
         final static String driver      = "sun.jdbc.odbc.JdbcOdbcDriver";
         final static String url      = "jdbc:odbc:addBKTAFE";
         final static String login      = "LOG-IN";
         final static String tab_login      = "Log-in";
         final static String tab1      = "INQUIRE Personnel Details";
         final static String tab2      = "UPDATE/DELETE Personnel Details";
         final static String tab3      = "INSERT Personnel Details";
         final static String insert      = "SAVE RECORD";
         final static String update           = "UPDATE RECORD";
         final static String delete      = "DELETE RECORD";
         final static String inquire      = "INQUIRE RECORD";
         final static String clear      = " CLEAR ";
         final static String relogin      = "Log-in failed! Please relog-in!";
         final static String norecfound      = "No Record Found!";
         final static String recinserted     = "Record Inserted!";
         final static String recupdated      = "Record Updated!";
         final static String recdeleted      = "Record Deleted!";
         final static String numericerror = "Age should be numeric!";
         final static String information = "INFORMATION";
         final static String error      = "ERROR";
         final static String genexception = "GENERAL EXCEPTION";
         final static String sqlexception = "SQL EXCEPTION";
         final static String confdelete = "CONFIRM DELETE";
         final static String slash      = "/";
         final static String table1      = "persons";
         final static String table2      = "Addresses";
    // Events events = new Events(this);
         // Define variables     for general use
         String sql = ""; // Used to store sql statements
         int pane_number = 0; // Used to indicate what screen needs to be processed
                                       // like resetting input fields and comboboxes
         boolean abort = false;// Used to indicate if error found to avoid further
                                       // processing/validations
         // Define container, panels and tabbedpane
    Container cntr = getContentPane();
    JTabbedPane tpane = new JTabbedPane();
         JPanel      cbpanel1 , cbpanel2 , cbpanel3,
                   panel1 , panel2 , panel3;
         // Setup constraints and type of layout
         GridBagConstraints constraints = new GridBagConstraints();
         GridBagConstraints constraints1 = new GridBagConstraints();
         GridBagConstraints constraints2 = new GridBagConstraints();
         GridBagConstraints constraints3 = new GridBagConstraints();
         GridBagLayout layout = new GridBagLayout ();
         // Define fonts to be used
         Font labelFont = new Font("Arial",Font.PLAIN,12);
         Font buttonFont = new Font("Arial",Font.BOLD,13);
         // Define labels
         JLabel lbUser      = new JLabel("Enter User ID: " );
         JLabel lbPassword      = new JLabel("Enter Password: ");
         JLabel lbSelectName      = new JLabel("Search Name: " );
         JLabel lbFirstName      = new JLabel("First Name: " );
         JLabel lbLastName      = new JLabel("Last Name: " );
         JLabel lbAddress           = new JLabel("Address: " );
         JLabel lbCity           = new JLabel("City" );
         JLabel lbState           = new JLabel("State: " );
         JLabel lbPostcode      = new JLabel("Postcode" );
    JLabel lbCountry           = new JLabel("Country" );
         JLabel lbEmailAddress      = new JLabel("Email Address: " );
    JLabel lbHomeNumber      = new JLabel("Home Phone No.: " );
    JLabel lbFaxNumber      = new JLabel("Fax No.: " );
         // Define combo boxes in third screen (insert pane)
         JComboBox cbName1          = new JComboBox();
         JComboBox cbPersonId1          = new JComboBox();
         // Define combo boxes in second (update/delete pane)
         JComboBox cbName2          = new JComboBox();
         JComboBox cbPersonId2          = new JComboBox();
         // Define buttons, text fields and password field
         JButton btLogin      = new JButton (login );
         JButton btInsert = new JButton (insert );
         JButton btUpdate      = new JButton (update );
         JButton btDelete      = new JButton (delete );
         JButton btInquire      = new JButton (inquire);
         JButton btClear      = new JButton (clear );
         JPasswordField jpPassword           = new JPasswordField(10 );
         JTextField tfUser           = new JTextField("",10 );
         // Inquiry fields on first screen (inquiry pane)
         JTextField tfFirstName1      = new JTextField("",30);
         JTextField tfLastName1           = new JTextField("",30);
         JTextField      tfAddress1          = new JTextField("",30);
         JTextField      tfCity1 = new JTextField("",15);
         JTextField      tfState1 = new JTextField("",15);
         JTextField      tfPostcode1      = new JTextField("",30);
         JTextField      tfCountry1          = new JTextField("",15 );
    JTextField      tfEmailAddress1      = new JTextField("",30);
    JTextField      tfHomeNumber1      = new JTextField("",15);
         JTextField      tfFaxNumber1           = new JTextField("",15 );
         // Input fields on second screen (update/delete pane)
         JTextField tfFirstName2      = new JTextField("",30);
         JTextField tfLastName2          = new JTextField("",30);
         JTextField      tfAddress2          = new JTextField("",30);
         JTextField      tfCity2 = new JTextField("",15);
         JTextField      tfState2 = new JTextField("",15);
         JTextField      tfPostcode2      = new JTextField("",30);
         JTextField      tfCountry2          = new JTextField("",15 );
    JTextField      tfEmailAddress2      = new JTextField("",30);
    JTextField      tfHomeNumber2      = new JTextField("",15);
         JTextField      tfFaxNumber2      = new JTextField("",15 );
         // Input fields on third screen (insert pane)
         JTextField tfFirstName3      = new JTextField("",30);
         JTextField tfLastName3          = new JTextField("",30);
         JTextField      tfAddress3          = new JTextField("",30);
         JTextField      tfCity3 = new JTextField("",15);
         JTextField      tfState3 = new JTextField("",15);
         JTextField      tfPostcode3      = new JTextField("",30);
         JTextField      tfCountry3          = new JTextField("",15 );
    JTextField      tfEmailAddress3      = new JTextField("",30);
    JTextField      tfHomeNumber3      = new JTextField("",15);
         JTextField      tfFaxNumber3           = new JTextField("",15 );
    //------------------------------------------------------------------------------>>>
    //-----------------------Start Addressbook()------------------------------------>>>
    Addressbook(){
    // define listener after adding items to CB to avoid triggering it
         //     cbName1.addItemListener(new ItemListener());
    // public void itemStateChanged(ItemEvent e){
    //--------------------------END Addressbook constructor------------------------------------->>>
    //------------------------------------------------------------------------------>>>
    //------------------------------------------------------------------------------>>>
    //--------------------Start setupLoginPanel()----------------------------------->>>
         // Setup the login screen
         public void setupLoginPanel(){
              // set application title
         setTitle("Address Book Application");
              // center screen
              setLocation((Toolkit.getDefaultToolkit().getScreenSize().width
                                  - getWidth())/2,
                        (Toolkit.getDefaultToolkit().getScreenSize().height
                             - getHeight())/2);
         panel1 = new JPanel();
              // set screen border
              panel1.setBorder(BorderFactory.createTitledBorder(
                                  BorderFactory.createEtchedBorder(),""));
              // add tabbedpane to panel
              tpane.addTab(tab_login, panel1);
              // add panel to container
              cntr.add(tpane);
              // setup layout as GridBagLayout
              constraints.insets = new Insets(2,2,2,2);
              panel1.setLayout(layout);
              // setup User ID label in display area
              lbUser.setFont(labelFont);
              constraints.ipadx = 2;
              constraints.ipady = 2;
              constraints.gridx = 0;
              constraints.gridy = 0;
              constraints.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbUser, constraints);
              panel1.add(lbUser);
              // setup User ID input field in display area
              tfUser.setFont(labelFont);
              constraints.ipadx = 2;
              constraints.ipady = 2;
              constraints.gridx = 1;
              constraints.gridy = 0;
              constraints.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(tfUser, constraints);
              panel1.add(tfUser);
              // setup Password label in display area
              lbPassword.setFont(labelFont);
              constraints.ipadx = 2;
              constraints.ipady = 2;
              constraints.gridx = 0;
              constraints.gridy = 1;
              constraints.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbPassword, constraints);
              panel1.add(lbPassword);
              // setup Password input field in display area
              jpPassword.setEchoChar('*');
              constraints.ipadx = 2;
              constraints.ipady = 2;
              constraints.gridx = 1;
              constraints.gridy = 1;
              layout.setConstraints(jpPassword, constraints);
              panel1.add(jpPassword);
              // setup Login button in display area
              btLogin.setFont(buttonFont);
              constraints.anchor = GridBagConstraints.WEST;
              constraints.gridy = 3;
              constraints.gridx = 1;
              layout.setConstraints(btLogin, constraints);
              panel1.add(btLogin);
              // setup login button listener
              btLogin.addActionListener(new ButtonHandler());
              // allow ALT L to press login button
              btLogin.setMnemonic('l');
    //--------------------End setupLoginPanel()------------------------------------->>>
    //--------------------Start login()--------------------------------------------->>>
         // Validate user input from the login screen based on information from login
         // table (note: manually create/update your login from table LOGIN).
         public void login(){
              String user = tfUser.getText();
              user = user.trim();
              char[] pw = jpPassword.getPassword();
    String password = new String(pw).trim();
              sql = "SELECT * FROM persons WHERE username='"+
                   user+"' AND password='"+password+"'";
              try{
                   // load MS Access driver
                   Class.forName(driver);
              }catch(java.lang.ClassNotFoundException ex){
                   JOptionPane.showMessageDialog(null,ex.getMessage(), error ,
                        JOptionPane.PLAIN_MESSAGE);
              try{
                   // setup connection to DBMS
                   Connection conn = DriverManager.getConnection(url);
                   // create statement
                   Statement stmt = conn.createStatement();
                   // execute sql statement
                   stmt.execute(sql);
                   ResultSet rs = stmt.getResultSet();
                   boolean recordfound = rs.next();
                   if (recordfound){
                        tpane.removeTabAt(0);
                        showPane1();
                        showPane2();
                        showPane3();
                   else{
                        // username/password invalid
                        JOptionPane.showMessageDialog(null,relogin, error,
                             JOptionPane.INFORMATION_MESSAGE);
                        //clear login and password fields
                        tfUser.setText ("");
                        jpPassword.setText("");
                   conn.close();
              }catch(Exception ex){
                   JOptionPane.showMessageDialog(null,ex.getMessage(), genexception,
                        JOptionPane.INFORMATION_MESSAGE);
    //--------------------End login()----------------------------------------------->>>
    //--------------------Start showPane1()----------------------------------------->>>
         // Setup screen 1(inquiry pane) including labels, input fields, comboboxes.
         // Table PERSONS is read to list inquiry parameters.
         void showPane1(){
              panel1 = new JPanel();
              cbpanel1 = new JPanel();
              // set screen border
              panel1.setBorder(BorderFactory.createTitledBorder(
                                  BorderFactory.createEtchedBorder(),""));
              // add tabbedpane to panel
              tpane.addTab(tab1, panel1);
              // setup layout as GridBagLayout
              constraints1.insets = new Insets(2,2,2,2);
              panel1.setLayout (layout);
              cbpanel1.setLayout (layout);
              // setup Name combobox label
              lbSelectName.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 0;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbSelectName, constraints1);
              panel1.add(lbSelectName);
              // setup Name combobox as search key
              cbName1.setFont(labelFont);
              constraints1.ipady = 10;
              constraints1.gridx = 1;
              constraints1.gridy = 0;
              constraints1.gridwidth = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              constraints1.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(cbName1, constraints1);
              panel1.add(cbName1);
              // setup search combobox (Name and corresponding key)
              cbName1.addItem ("Choose one:");
              cbPersonId1.addItem("0");
              // setup First Name label in display area
              lbFirstName.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 1;
              constraints1.anchor = GridBagConstraints.WEST;
              constraints1.fill = GridBagConstraints.NONE;
              constraints1.gridwidth = 1;
              layout.setConstraints(lbFirstName, constraints1);
              panel1.add(lbFirstName);
              // setup First Name input field in display area
              tfFirstName1.setFont(labelFont);
              tfFirstName1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 1;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFirstName1, constraints1);
              panel1.add(tfFirstName1);
              // setup Last Name label in display area
              lbLastName.setFont(labelFont);
              constraints1.gridx = 2;
              constraints1.gridy = 1;
              constraints1.anchor = GridBagConstraints.WEST;
              constraints1.fill = GridBagConstraints.NONE;
              layout.setConstraints(lbLastName, constraints1);
              panel1.add(lbLastName);
              // setup Last Name input field in display area
              tfLastName1.setFont(labelFont);
              tfLastName1.setEditable(false);
              constraints1.gridx = 3;
              constraints1.gridy = 1;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfLastName1, constraints1);
              panel1.add(tfLastName1);
              // setup Address label in display area
              lbAddress.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 2;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbAddress, constraints1);
              panel1.add(lbAddress);
              // setup Address input field in display area
              tfAddress1.setFont(labelFont);
              tfAddress1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 2;
              constraints1.gridwidth = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              constraints1.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(tfAddress1, constraints1);
              panel1.add(tfAddress1);
              // setup City label in display area
              lbCity.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbCity, constraints1);
              panel1.add(lbCity);
              // setup City input field in display area
              tfCity1.setFont(labelFont);
              tfCity1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfCity1, constraints1);
              panel1.add(tfCity1);
              // setup State label in display area
              lbState.setFont(labelFont);
              constraints1.gridx = 2;
              constraints1.gridy = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbState, constraints1);
              panel1.add(lbState);
              // setup State input field in display area
              tfState1.setFont(labelFont);
              tfState1.setEnabled(false);
              constraints1.gridx = 3;
              constraints1.gridy = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfState1, constraints1);
              panel1.add(tfState1);
              // setup Postcode label in display area
              lbPostcode.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 4;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbPostcode, constraints1);
              panel1.add(lbPostcode);
              // setup Address input field in display area
              tfPostcode1.setFont(labelFont);
              tfPostcode1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 4;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfPostcode1, constraints1);
              panel1.add(tfPostcode1);
              // setup Country label in display area
              lbCountry.setFont(labelFont);
              constraints1.gridx = 2;
              constraints1.gridy = 4;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbCountry, constraints1);
              panel1.add(lbCountry);
              // setup Country input field in display area
              tfCountry1.setFont(labelFont);
              tfCountry1.setEditable(false);
              constraints1.gridx = 3;
              constraints1.gridy = 4;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfCountry1, constraints1);
              panel1.add(tfCountry1);
              // setup Email Address label in display area
              lbEmailAddress = new JLabel ("Email Address:");
              lbEmailAddress.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 5;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbEmailAddress, constraints1);
              panel1.add(lbEmailAddress);
              // setup Email Address input field in display area
              tfEmailAddress1.setFont(labelFont);
              constraints1.gridx = 1;
              constraints1.gridy = 5;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfEmailAddress1, constraints1);
              panel1.add(tfEmailAddress1);
              // setup Home Phone Number label in display area
              lbHomeNumber.setFont(labelFont);
              constraints1.gridx = 2;
              constraints1.gridy = 5;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbHomeNumber, constraints1);
              panel1.add(lbHomeNumber);
              // setup Home Phone Number input field in display area
              tfHomeNumber1.setFont(labelFont);
              tfHomeNumber1.setEditable(false);
              constraints1.gridx = 3;
              constraints1.gridy = 5;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfHomeNumber1, constraints1);
              panel1.add(tfHomeNumber1);
              // setup Fax Number label in display area
              lbFaxNumber.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 6;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbFaxNumber, constraints1);
              panel1.add(lbFaxNumber);
              // setup Fax Number input field in display area
              tfFaxNumber1.setFont(labelFont);
              tfFaxNumber1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 6;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFaxNumber1, constraints1);
              panel1.add(tfFaxNumber1);
    // indicate inquiry pane
              pane_number = 1;
              // read table get the list of names in CB search key
         accessDBInit();
              // define listener after adding items to CB to avoid triggering it
              cbName1.addItemListener(new ComboBoxHandler());
    //--------------------End showPane1()------------------------------------------->>>
    //--------------------Start showPane2()----------------------------------------->>>
         // Setup screen 2(update and delete pane) including labels, input fields,
         // comboboxes, and buttons. Table PERSONS is read to list inquiry parameters.
         void showPane2(){
              panel2 = new JPanel();
              cbpanel2 = new JPanel();
              labelFont = new Font("Arial",Font.PLAIN,12);
              buttonFont = new Font("Arial",Font.BOLD,12);
              // set screen border
              panel2.setBorder(BorderFactory.createTitledBorder(
                   BorderFactory.createEtchedBorder(),""));
              // add tabbedpane to panel
              tpane.addTab(tab2, panel2);
              // setup layout as GridBagLayout
              constraints2.insets = new Insets(2,2,2,2);
              panel2.setLayout (layout);
              cbpanel2.setLayout (layout);
              // setup Name combobox label
              lbSelectName.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 0;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbSelectName, constraints2);
              panel1.add(lbSelectName);
              // setup Name combobox as search key
              cbName2.setFont(labelFont);
              constraints2.ipady = 10;
              constraints2.gridx = 1;
              constraints2.gridy = 0;
              constraints2.gridwidth = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              constraints2.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(cbName1, constraints2);
              panel1.add (cbName1);
              // setup search combobox (Name and corresponding key)
              cbName1.addItem ("Choose one:");
              cbPersonId1.addItem("0");
              // setup First Name label in display area
              lbFirstName.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 1;
              constraints2.anchor = GridBagConstraints.WEST;
              constraints2.fill = GridBagConstraints.NONE;
              constraints2.gridwidth = 1;
              layout.setConstraints(lbFirstName, constraints2);
              panel1.add(lbFirstName);
              // setup First Name input field in display area
              tfFirstName2.setFont(labelFont);
              tfFirstName2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 1;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFirstName2, constraints2);
              panel1.add(tfFirstName2);
              // setup Last Name label in display area
              lbLastName.setFont(labelFont);
              constraints2.gridx = 2;
              constraints2.gridy = 1;
              constraints2.anchor = GridBagConstraints.WEST;
              constraints2.fill = GridBagConstraints.NONE;
              layout.setConstraints(lbLastName, constraints2);
              panel1.add(lbLastName);
              // setup Last Name input field in display area
              tfLastName2.setFont(labelFont);
              tfLastName2.setEditable(false);
              constraints2.gridx = 3;
              constraints2.gridy = 1;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfLastName2, constraints2);
              panel1.add(tfLastName2);
              // setup Address label in display area
              lbAddress.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 2;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbAddress, constraints2);
              panel1.add(lbAddress);
              // setup Address input field in display area
              tfAddress2.setFont(labelFont);
              tfAddress2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 2;
              constraints2.gridwidth = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              constraints2.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(tfAddress2, constraints2);
              panel1.add(tfAddress2);
              // setup City label in display area
              lbCity.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbCity, constraints2);
              panel1.add(lbCity);
              // setup City input field in display area
              tfCity2.setFont(labelFont);
              tfCity2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfCity2, constraints2);
              panel1.add(tfCity2);
              // setup State label in display area
              lbState.setFont(labelFont);
              constraints2.gridx = 2;
              constraints2.gridy = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbState, constraints2);
              panel1.add(lbState);
              // setup State input field in display area
              tfState2.setFont(labelFont);
              tfState2.setEnabled(false);
              constraints2.gridx = 3;
              constraints2.gridy = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfState2, constraints2);
              panel1.add(tfState2);
              // indicate inquiry pane
              pane_number = 1;
              // setup Address label in display area
              lbPostcode.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 4;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbPostcode, constraints2);
              panel1.add(lbPostcode);
              // setup Address input field in display area
              tfPostcode2.setFont(labelFont);
              tfPostcode2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 4;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfPostcode2, constraints2);
              panel1.add(tfPostcode2);
              // setup Country label in display area
              lbCountry.setFont(labelFont);
              constraints2.gridx = 2;
              constraints2.gridy = 4;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbCountry, constraints2);
              panel1.add(lbCountry);
              // setup Country input field in display area
              tfCountry2.setFont(labelFont);
              tfCountry2.setEditable(false);
              constraints2.gridx = 3;
              constraints2.gridy = 4;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfCountry2, constraints2);
              panel1.add(tfCountry2);
              // setup Email Address label in display area
              lbEmailAddress = new JLabel ("Email Address:");
              lbEmailAddress.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 5;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbEmailAddress, constraints2);
              panel1.add(lbEmailAddress);
              // setup Email Address input field in display area
              tfEmailAddress2.setFont(labelFont);
              constraints2.gridx = 1;
              constraints2.gridy = 5;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfEmailAddress2, constraints2);
              panel1.add(tfEmailAddress2);
              // setup Home Phone Number label in display area
              lbHomeNumber.setFont(labelFont);
              constraints2.gridx = 2;
              constraints2.gridy = 5;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbHomeNumber, constraints2);
              panel1.add(lbHomeNumber);
              // setup Home Phone Number input field in display area
              tfHomeNumber2.setFont(labelFont);
              tfHomeNumber2.setEditable(false);
              constraints2.gridx = 3;
              constraints2.gridy = 5;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfHomeNumber2, constraints2);
              panel1.add(tfHomeNumber2);
              // setup Fax Number label in display area
              lbFaxNumber.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 6;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbFaxNumber, constraints2);
              panel1.add(lbFaxNumber);
              // setup Fax Number input field in display area
              tfFaxNumber2.setFont(labelFont);
              tfFaxNumber2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 6;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFaxNumber2, constraints2);
              panel1.add(tfFaxNumber2);
              // setup UPDATE button in display area
              btUpdate.setFont(buttonFont);
              constraints2.gridx = 3;
              constraints2.gridy = 7;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(btUpdate, constraints2);
              panel2.add(btUpdate);
              // setup DELETE button in display area
              btDelete.setFont(buttonFont);
              constraints2.gridx = 1;
              constraints2.gridy = 7;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(btDelete, constraints2);
              panel2.add(btDelete);
              btUpdate.addActionListener(new ButtonHandler());
              btDelete.addActionListener(new ButtonHandler());
              // allow ALT U to press update button
              btUpdate.setMnemonic('u');
              // allow ALT D to press delete button
              btDelete.setMnemonic('d');
              // read table get the list of names in combo box search key
    accessDBInit();
              // define listener after adding items to CB to avoid triggering it
              cbName2.addItemListener(new ComboBoxHandler());
    //--------------------End showPane2()------------------------------------------->>>
    //--------------------Start showPane3()----------------------------------------->>>
         // Setup screen 2(insert pane) including labels, input fields, comboboxes,
         // and buttons.
         void showPane3(){
              panel3      = new JPanel();
              // set screen border
              panel3.setBorder(BorderFactory.createTitledBorder(
                   BorderFactory.createEtchedBorder(),""));
              // add tabbedpane to panel
              tpane.addTab(tab3, panel3);
              // setup layout as GridBagLayout
              constraints3.insets = new Insets(2,2,2,2);
              panel3.setLayout (layout);
              // setup First Name label in display area
              JLabel lbFirstName = new JLabel("First Name:");
              lbFirstName.setFont(labelFont);
              constraints3.gridx = 0;
              constraints3.gridy = 0;
              constraints3.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbFirstName, constraints3);
              panel3.add(lbFirstName);
              // setup First Name input field in display area
              tfFirstName3.setFont(labelFont);
              constraints3.ipady = 8; // adjust heigth of input field
              constraints3.gridx = 1;
              constraints3.gridy = 0;
              constraints3.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFirstName3, constraints3);
              panel3.add(tfFirstName3);
              // setup Last Name label in display area
              lbLastName = new JLabel("Last Name: ");
              lbLastName.setFont(labelFont);
              constraints3.gridx = 2;
              constraints3.gridy = 0;
              constraints3.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbLastName, constraints3);
              panel3.add(lbLastName);
              // setup Last Name input field in display area
              tfLastName3.setFont(labelFont);
              constraints3.gridx = 3;
              constraints3.gridy = 0;
              constraints3.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfLastName3, constraints3);
              panel3.add(tfLastName3);
              // setup Middle Name label in display area
              lbAddress = new JLabel("Address: ");
              lbAddress.setFont(labelFont);
              constraints3.gridx = 0;
              constraints3.gridy = 1;
              constraints3.anch

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class andy extends JFrame {
      // Define constant variables
      final static String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
      final static String url = "jdbc:odbc:addBKTAFE";
      final static String login = "LOG-IN";
      final static String tab_login = "Log-in";
      final static String tab1 = "INQUIRE Personnel Details";
      final static String tab2 = "UPDATE/DELETE Personnel Details";
      final static String tab3 = "INSERT Personnel Details";
      final static String tab4 = "PRINT";
      final static String insert = "SAVE RECORD";
      final static String update = "UPDATE RECORD";
      final static String delete = "DELETE RECORD";
      final static String inquire = "INQUIRE RECORD";
      final static String clear = " CLEAR ";
      final static String relogin = "Log-in failed! Please relog-in!";
      final static String norecfound = "No Record Found!";
      final static String recinserted = "Record Inserted!";
      final static String recupdated = "Record Updated!";
      final static String recdeleted = "Record Deleted!";
      final static String numericerror = "Age should be numeric!";
      final static String information = "INFORMATION";
      final static String error = "ERROR";
      final static String genexception = "GENERAL EXCEPTION";
      final static String sqlexception = "SQL EXCEPTION";
      final static String confdelete = "CONFIRM DELETE";
      final static String slash = "/";
      final static String table1 = "persons";
      final static String table2 = "Addresses";
      // Define container, panels and tabbedpane
      Container cntr = getContentPane();
      JTabbedPane tpane = new JTabbedPane();
      JPanel cbpanel1 , cbpanel2 , cbpanel3,
             panel1 , panel2 , panel3, panel4;
      // Define fonts to be used
      Font labelFont = new Font("Arial",Font.PLAIN,12);
      Font buttonFont = new Font("Arial",Font.BOLD,13);
      // Define labels
      JLabel lbUser = new JLabel("Enter User ID: " );
      JLabel lbPassword = new JLabel("Enter Password: ");
      JLabel lbSelectName = new JLabel("Search Name: " );
      JLabel lbFirstName = new JLabel("First Name: " );
      JLabel lbLastName = new JLabel("Last Name: " );
      JLabel lbAddress = new JLabel("Address: " );
      JLabel lbCity = new JLabel("City: " );
      JLabel lbState = new JLabel("State: " );
      JLabel lbPostcode = new JLabel("Postcode: " );
      JLabel lbCountry = new JLabel("Country: " );
      JLabel lbEmailAddress = new JLabel("Email Address: " );
      JLabel lbHomeNumber = new JLabel("Home Phone No.: " );
      JLabel lbFaxNumber = new JLabel("Fax No.: " );
      // Define combo boxes in third screen (insert pane)
      JComboBox cbName1     = new JComboBox();
      JComboBox cbName2     = new JComboBox();
      JComboBox cbName3     = new JComboBox();
      JComboBox cbPersonId1 = new JComboBox();
      JComboBox cbPersonId2 = new JComboBox();
      JComboBox cbPersonId3 = new JComboBox();
      // Inquiry fields on first screen (inquiry pane)
      JTextField tfFirstName1 = new JTextField("",30);
      JTextField tfLastName1 = new JTextField("",30);
      JTextField tfAddress1 = new JTextField("",30);
      JTextField tfCity1 = new JTextField("",15);
      JTextField tfState1 = new JTextField("",15);
      JTextField tfPostcode1 = new JTextField("",30);
      JTextField tfCountry1 = new JTextField("",15 );
      JTextField tfEmailAddress1 = new JTextField("",30);
      JTextField tfHomeNumber1 = new JTextField("",15);
      JTextField tfFaxNumber1 = new JTextField("",15 );
      // Input fields on second screen (update/delete pane)
      JTextField tfFirstName2 = new JTextField("",30);
      JTextField tfLastName2 = new JTextField("",30);
      JTextField tfAddress2 = new JTextField("",30);
      JTextField tfCity2 = new JTextField("",15);
      JTextField tfState2 = new JTextField("",15);
      JTextField tfPostcode2 = new JTextField("",30);
      JTextField tfCountry2 = new JTextField("",15);
      JTextField tfEmailAddress2 = new JTextField("",30);
      JTextField tfHomeNumber2 = new JTextField("",15);
      JTextField tfFaxNumber2 = new JTextField("",15);
      // Input fields on third screen (inset details pane)
      JTextField tfFirstName3 = new JTextField("",30);
      JTextField tfLastName3 = new JTextField("",30);
      JTextField tfAddress3 = new JTextField("",30);
      JTextField tfCity3 = new JTextField("",15);
      JTextField tfState3 = new JTextField("",15);
      JTextField tfPostcode3 = new JTextField("",30);
      JTextField tfCountry3 = new JTextField("",15);
      JTextField tfEmailAddress3 = new JTextField("",30);
      JTextField tfHomeNumber3 = new JTextField("",15);
      JTextField tfFaxNumber3 = new JTextField("",15);
      GridBagLayout layout = new GridBagLayout();
      GridBagConstraints constraints = new GridBagConstraints();
      public andy() {
        super("Address Book Application");
        showPane1();
        showPane2();
        showPane3();
        showPane4();
        cntr.add(tpane, "Center");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(900,385);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((screenSize.width  - getWidth())/2,
                    (screenSize.height - getHeight())/2);
        setVisible(true);
      // Setup screen 1(inquiry pane) including labels, input fields, comboboxes.
      // Table PERSONS is read to list inquiry parameters.
      void showPane1() {
        panel1 = new JPanel();
        cbpanel1 = new JPanel();
        // set screen border
        panel1.setBorder(BorderFactory.createTitledBorder(
          BorderFactory.createEtchedBorder(),""));
        // add tabbedpane to panel
        tpane.addTab(tab1, panel1);
        // setup layout as GridBagLayout
        constraints.insets = new Insets(2,2,2,2);
        panel1.setLayout (layout);
        cbpanel1.setLayout (layout);
        // setup Name combobox label
        lbSelectName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbSelectName, constraints);
        panel1.add(lbSelectName);
        // setup Name combobox as search key
        cbName1.setFont(labelFont);
        constraints.ipady = 10;
        constraints.gridwidth = constraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(cbName1, constraints);
        panel1.add(cbName1);
        // setup search combobox (Name and corresponding key)
        cbName1.addItem ("Choose one:");
        cbPersonId1.addItem("0");
        // setup First Name label in display area
        lbFirstName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFirstName, constraints);
        panel1.add(lbFirstName);
        // setup First Name input field in display area
        tfFirstName1.setFont(labelFont);
        tfFirstName1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFirstName1, constraints);
        panel1.add(tfFirstName1);
        // setup Last Name label in display area
        lbLastName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbLastName, constraints);
        panel1.add(lbLastName);
        // setup Last Name input field in display area
        tfLastName1.setFont(labelFont);
        tfLastName1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfLastName1, constraints);
        panel1.add(tfLastName1);
        // setup Address label in display area
        lbAddress.setFont(labelFont);
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbAddress, constraints);
        panel1.add(lbAddress);
        // setup Address input field in display area
        tfAddress1.setFont(labelFont);
        tfAddress1.setEditable(false);
        constraints.gridwidth = constraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.weightx = 1.0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        layout.setConstraints(tfAddress1, constraints);
        panel1.add(tfAddress1);
        // setup City label in display area
        lbCity.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        constraints.fill = GridBagConstraints.NONE;
            layout.setConstraints(lbCity, constraints);
        panel1.add(lbCity);
        // setup City input field in display area
        tfCity1.setFont(labelFont);
        tfCity1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfCity1, constraints);
        panel1.add(tfCity1);
        // setup State label in display area
        lbState.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbState, constraints);
        panel1.add(lbState);
        // setup State input field in display area
        tfState1.setFont(labelFont);
        tfState1.setEnabled(false);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfState1, constraints);
        panel1.add(tfState1);
        // setup Postcode label in display area
        lbPostcode.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbPostcode, constraints);
        panel1.add(lbPostcode);
        // setup Address input field in display area
        tfPostcode1.setFont(labelFont);
        tfPostcode1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfPostcode1, constraints);
        panel1.add(tfPostcode1);
        // setup Country label in display area
        lbCountry.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbCountry, constraints);
        panel1.add(lbCountry);
        // setup Country input field in display area
        tfCountry1.setFont(labelFont);
        tfCountry1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfCountry1, constraints);
        panel1.add(tfCountry1);
        // setup Email Address label in display area
        lbEmailAddress.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbEmailAddress, constraints);
        panel1.add(lbEmailAddress);
        // setup Email Address input field in display area
        tfEmailAddress1.setFont(labelFont);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfEmailAddress1, constraints);
        panel1.add(tfEmailAddress1);
        // setup Home Phone Number label in display area
        lbHomeNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbHomeNumber, constraints);
        panel1.add(lbHomeNumber);
        // setup Home Phone Number input field in display area
        tfHomeNumber1.setFont(labelFont);
        tfHomeNumber1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfHomeNumber1, constraints);
        panel1.add(tfHomeNumber1);
        // setup Fax Number label in display area
        lbFaxNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFaxNumber, constraints);
        panel1.add(lbFaxNumber);
        // setup Fax Number input field in display area
        tfFaxNumber1.setFont(labelFont);
        tfFaxNumber1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFaxNumber1, constraints);
        panel1.add(tfFaxNumber1);
        // indicate inquiry pane
        // pane_number = 1;
        // read table get the list of names in CB search key
        // accessDBInit();
        // define listener after adding items to CB to avoid triggering it
        // cbName1.addItemListener(new ComboBoxHandler());
      //--------------------End showPane1()------------------------------------------->>>
      //--------------------Start showPane2()----------------------------------------->>>
      void showPane2() {
        panel2 = new JPanel();
        cbpanel2 = new JPanel();
        // set screen border
        panel2.setBorder(BorderFactory.createTitledBorder(
          BorderFactory.createEtchedBorder(),""));
        // add tabbedpane to panel
        tpane.addTab(tab2, panel2);
        // setup layout as GridBagLayout
        constraints.ipady = 0;
        panel2.setLayout (layout);
        cbpanel2.setLayout (layout);
        // setup Name combobox label
        lbSelectName = new JLabel("Search Name: ");
        lbSelectName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbSelectName, constraints);
        panel2.add(lbSelectName);
        // setup Name combobox as search key
        cbName2.setFont(labelFont);
        constraints.ipady = 10;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(cbName2, constraints);
        panel2.add(cbName2);
        // setup search combobox (Name and corresponding key)
        cbName2.addItem ("Choose one:");
        cbPersonId2.addItem("0");
        // setup UPDATE button in display area
        JButton btUpdate = new JButton("Update");
        btUpdate.setFont(buttonFont);
    //    btUpdate.addActionListener(new ButtonHandler());
        btUpdate.setMnemonic(KeyEvent.VK_U);
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(btUpdate, constraints);
        panel2.add(btUpdate);
        // setup DELETE button in display area
        JButton btDelete = new JButton("Delete");
        btDelete.setFont(buttonFont);
    //    btDelete.addActionListener(new ButtonHandler());
        btDelete.setMnemonic(KeyEvent.VK_D);
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(btDelete, constraints);
        panel2.add(btDelete);
        // setup First Name label in display area
        lbFirstName = new JLabel("First Name: ");
        lbFirstName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFirstName, constraints);
        panel2.add(lbFirstName);
        // setup First Name input field in display area
        tfFirstName2.setFont(labelFont);
        tfFirstName2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFirstName2, constraints);
        panel2.add(tfFirstName2);
        // setup Last Name label in display area
        lbLastName = new JLabel("Last Name: ");
        lbLastName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbLastName, constraints);
        panel2.add(lbLastName);
        // setup Last Name input field in display area
        tfLastName2.setFont(labelFont);
        tfLastName2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfLastName2, constraints);
        panel2.add(tfLastName2);
        // setup Address label in display area
        lbAddress = new JLabel("Address: ");
        lbAddress.setFont(labelFont);
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbAddress, constraints);
        panel2.add(lbAddress);
        // setup Address input field in display area
        tfAddress2.setFont(labelFont);
        tfAddress2.setEditable(true);
        constraints.gridwidth = constraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.weightx = 1.0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        layout.setConstraints(tfAddress2, constraints);
        panel2.add(tfAddress2);
        // setup City label in display area
        lbCity = new JLabel("City: ");
        lbCity.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        constraints.fill = GridBagConstraints.NONE;
        layout.setConstraints(lbCity, constraints);
        panel2.add(lbCity);
        // setup City input field in display area
        tfCity2.setFont(labelFont);
        tfCity2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfCity2, constraints);
        panel2.add(tfCity2);
        // setup State label in display area
        lbState = new JLabel("State: ");
        lbState.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbState, constraints);
        panel2.add(lbState);
        // setup State input field in display area
        tfState2.setFont(labelFont);
        tfState2.setEnabled(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfState2, constraints);
        panel2.add(tfState2);
        // setup Postcode label in display area
        lbPostcode = new JLabel("Postcode: ");
        lbPostcode.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbPostcode, constraints);
        panel2.add(lbPostcode);
        // setup Address input field in display area
        tfPostcode2.setFont(labelFont);
        tfPostcode2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfPostcode2, constraints);
        panel2.add(tfPostcode2);
        // setup Country label in display area
        lbCountry = new JLabel("Country: ");
        lbCountry.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbCountry, constraints);
        panel2.add(lbCountry);
        // setup Country input field in display area
        tfCountry2.setFont(labelFont);
        tfCountry2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfCountry2, constraints);
        panel2.add(tfCountry2);
        // setup Email Address label in display area
        lbEmailAddress = new JLabel ("Email Address: ");
        lbEmailAddress.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbEmailAddress, constraints);
        panel2.add(lbEmailAddress);
        // setup Email Address input field in display area
        tfEmailAddress2.setFont(labelFont);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfEmailAddress2, constraints);
        panel2.add(tfEmailAddress2);
        // setup Home Phone Number label in display area
        lbHomeNumber = new JLabel("Home Phone No.: ");
        lbHomeNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbHomeNumber, constraints);
        panel2.add(lbHomeNumber);
        // setup Home Phone Number input field in display area
        tfHomeNumber2.setFont(labelFont);
        tfHomeNumber2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfHomeNumber2, constraints);
        panel2.add(tfHomeNumber2);
        // setup Fax Number label in display area
        lbFaxNumber = new JLabel("Fax No.: ");
        lbFaxNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFaxNumber, constraints);
        panel2.add(lbFaxNumber);
        // setup Fax Number input field in display area
        tfFaxNumber2.setFont(labelFont);
        tfFaxNumber2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFaxNumber2, constraints);
        panel2.add(tfFaxNumber2);
      //-----------------------------End showpane2()---------------------------------->>
      //--------------------Start showPane3()----------------------------------------->>>
      void showPane3() {
        panel3 = new JPanel();
        // cbpanel3 = new JPanel();
        // set screen border
        panel3.setBorder(BorderFactory.createTitledBorder(
          BorderFactory.createEtchedBorder(),""));
        // add tabbedpane to panel
        tpane.addTab(tab3, panel3);
        // setup layout as GridBagLayout
        panel3.setLayout(layout);
        constraints.ipady = 0;
        panel3.setLayout (layout);
        // cbpanel3.setLayout (layout);
        // setup Name combobox label
        lbSelectName = new JLabel("Search Name: ");
        lbSelectName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbSelectName, constraints);
        panel3.add(lbSelectName);
        // setup Name combobox as search key
        cbName3 = new JComboBox();
        cbName3.setFont(labelFont);
        constraints.ipady = 10;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(cbName3, constraints);
        panel3.add(cbName3);
        // setup search combobox (Name and corresponding key)
        cbName3.addItem ("Choose one:");
        cbPersonId3.addItem("0");
        // setup INSERT button in display area
        JButton btInsert = new JButton("Insert");
        btInsert.setFont(buttonFont);
    //    btInsert.addActionListener(new ButtonListener());
        btInsert.setMnemonic(KeyEvent.VK_S);
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(btInsert, constraints);
        panel3.add(btInsert);
        // setup CLEAR button in display area
        JButton btClear = new JButton("Clear");
        btClear.setFont(buttonFont);
    //    btClear.addActionListener(new ButtonListener());
        btClear.setMnemonic(KeyEvent.VK_C);
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(btClear, constraints);
        panel3.add(btClear);
        // setup First Name label in display area
        lbFirstName = new JLabel("First Name: ");
        lbFirstName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFirstName, constraints);
        panel3.add(lbFirstName);
        // setup First Name input field in display area
        tfFirstName3.setFont(labelFont);
        tfFirstName3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFirstName3, constraints);
        panel3.add(tfFirstName3);
        // setup Last Name label in display area
        lbLastName = new JLabel("Last Name: ");
        lbLastName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbLastName, constraints);
        panel3.add(lbLastName);
        // setup Last Name input field in display area
        tfLastName3.setFont(labelFont);
        tfLastName3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfLastName3, constraints);
        panel3.add(tfLastName3);
        // setup Address label in display area
        lbAddress = new JLabel("Address: ");
        lbAddress.setFont(labelFont);
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbAddress, constraints);
        panel3.add(lbAddress);
        // setup Address input field in display area
        tfAddress3.setFont(labelFont);
        tfAddress3.setEditable(true);
        constraints.gridwidth = constraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.weightx = 1.0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        layout.setConstraints(tfAddress3, constraints);
        panel3.add(tfAddress3);
        // setup City label in display area
        lbCity = new JLabel("City: ");
        lbCity.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        constraints.fill = GridBagConstraints.NONE;
        layout.setConstraints(lbCity, constraints);
        panel3.add(lbCity);
        // setup City input field in display area
        tfCity3.setFont(labelFont);
        tfCity3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfCity3, constraints);
        panel3.add(tfCity3);
        // setup State label in display area
        lbState = new JLabel("State: ");
        lbState.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbState, constraints);
        panel3.add(lbState);
        // setup State input field in display area
        tfState3.setFont(labelFont);
        tfState3.setEnabled(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfState3, constraints);
        panel3.add(tfState3);
        // setup Postcode label in display area
        lbPostcode = new JLabel("Postcode: ");
        lbPostcode.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbPostcode, constraints);
        panel3.add(lbPostcode);
        // setup Address input field in display area
        tfPostcode3.setFont(labelFont);
        tfPostcode3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfPostcode3, constraints);
        panel3.add(tfPostcode3);
        // setup Country label in display area
        lbCountry = new JLabel("Country: ");
        lbCountry.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbCountry, constraints);
        panel3.add(lbCountry);
        // setup Country input field in display area
        tfCountry3.setFont(labelFont);
        tfCountry3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfCountry3, constraints);
        panel3.add(tfCountry3);
        // setup Email Address label in display area
        lbEmailAddress = new JLabel ("Email Address: ");
        lbEmailAddress.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbEmailAddress, constraints);
        panel3.add(lbEmailAddress);
        // setup Email Address input field in display area
        tfEmailAddress3.setFont(labelFont);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfEmailAddress3, constraints);
        panel3.add(tfEmailAddress3);
        // setup Home Phone Number label in display area
        lbHomeNumber = new JLabel("Home Phone No.: ");
        lbHomeNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbHomeNumber, constraints);
        panel3.add(lbHomeNumber);
        // setup Home Phone Number input field in display area
        tfHomeNumber3.setFont(labelFont);
        tfHomeNumber3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfHomeNumber3, constraints);
        panel3.add(tfHomeNumber3);
        // setup Fax Number label in display area
        lbFaxNumber = new JLabel("Fax No.: ");
        lbFaxNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFaxNumber, constraints);
        panel3.add(lbFaxNumber);
        // setup Fax Number input field in display area
        tfFaxNumber3.setFont(labelFont);
        tfFaxNumber3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFaxNumber3, constraints);
        panel3.add(tfFaxNumber3);
      //-----------------------------End showpane3()---------------------------------->>
      //-----------------------------Start showPane4()-------------------------------->>
      void showPane4() {
    //    qtm = new QueryTableModel();
    //    JTable table = new JTable(qtm);
    //    String query = "SELECT FirstName, LastName, HomePhone, " +
    //                   "FROM Addresses ORDER By LastName";
    //    qtm.setQuery(query);
        JPanel demoPanel = new JPanel();
        demoPanel.setPreferredSize(new Dimension(400,500));
        demoPanel.setBackground(Color.pink);
        demoPanel.add(new JLabel("Demo Panel in place of table",
                                  SwingConstants.CENTER));
        JScrollPane scrollPane = new JScrollPane(demoPanel);
        panel4 = new JPanel();
    //    pane_number = 4;
        panel4.setLayout(layout);
        constraints.ipady = 0;
    //    labelFont = new Font("Arial", Font.PLAIN, 12);   defined above
        buttonFont = new Font("Arial", Font.PLAIN, 13);
       // set screen border
       panel4.setBorder(
         BorderFactory.createTitledBorder(
           BorderFactory.createEtchedBorder(), ""));
       // add panel to tabbed pane
       tpane.addTab(tab4, panel4);
       JLabel lbPrint = new JLabel("Print");
       lbPrint.setFont(labelFont);
       constraints.anchor = constraints.EAST;
       layout.setConstraints(lbPrint, constraints);
       panel4.add(lbPrint);
       JButton btPrint = new JButton("Print");
       btPrint.setFont(buttonFont);
    //   btPrint.addActionListener(new ButtonListener());
       btPrint.setMnemonic(KeyEvent.VK_P);
       constraints.anchor = constraints.WEST;
       constraints.gridwidth = constraints.REMAINDER;
       layout.setConstraints(btPrint, constraints);
       panel4.add(btPrint);
       constraints.weighty = 1.0;
       constraints.fill = constraints.BOTH;
       constraints.anchor = constraints.CENTER;
       layout.setConstraints(scrollPane, constraints);
       panel4.add(scrollPane);
      public static void main(String[] args) {
        new andy();
    }

Maybe you are looking for