• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Layout

import java.awt.*;
import java.awt.event.*;

public class TextDisplayFrame extends Frame
{
      Label lbl;
      TextField tf;
      TextArea ta;
      Button bOK,bclr,bAppend;
      Checkbox cBold, cItalic;
      TextDisplayHandler theHandler;
      
      public TextDisplayFrame()
      {
             setTitle("Hello Kitty");
             setSize(500,500);
             
             setLayout(new GridLayout(4,0));
             
             lbl = new Label("Enter some text:");
             tf = new TextField(15);
             bclr = new Button("Clear");
             bOK = new Button("OK");
             bAppend = new Button("Append");
             cBold = new Checkbox("Bold");
             cItalic = new Checkbox("Italic");
             ta = new TextArea("Hello", 5, 40);
             
             theHandler = new TextDisplayHandler(this);
             
             bclr.addActionListener(theHandler);
             bOK.addActionListener(theHandler);
             bAppend.addActionListener(theHandler);
             tf.addActionListener(theHandler);
             
             
             Panel p1 = new Panel(new FlowLayout());       
             Panel p2 = new Panel(new FlowLayout());
             Panel p3 = new Panel(new FlowLayout());
             Panel p4 = new Panel(new FlowLayout());
          
             p1.add(lbl);
             p1.add(tf);
             
             p2.add(cBold);
             p2.add(cItalic);
             
             p3.add(bclr);
             p3.add(bOK);
             p3.add(bAppend);
             
             p4.add(ta);
               
             add(p1);
             add(p2);
             add(p3);
             add(p4);
       }
      
       public static void main(String[] args)
       {
              Frame fr = new TextDisplayFrame();
              fr.addWindowListener(new AppCloser());
              fr.show();
       }
      
       static class AppCloser extends WindowAdapter
       {
              public void windowClosing(WindowEvent we)
              {
                       System.exit(0);
              }
       }
}

The problem I am facing is the distance between the panel 1 - 4. So much space between the panels. How do I solve this problem?

Your help is kindly appreciated.

Regards

Eugene
0
eugene007
Asked:
eugene007
  • 4
  • 2
2 Solutions
 
suprapto45Commented:
Mmm...

You can put all of these in one panel (Gridlayout 4, 0) and you put this panel on BorderLayout. let me show you same sample.

Regards
Dave
0
 
suprapto45Commented:
Alternatively,

You can set the frame to be "not that big" to squeze the panel.

Regards
Dave
0
 
suprapto45Commented:
Or,

use GridBagLayout for more free-features GUI location

Regards
Dave
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
suprapto45Commented:
0
 
aozarovCommented:
Do you want your pannels to be one after the other?
then change: setLayout(new GridLayout(4,0));
to
setLayout(new GridLayout(4,1));

though you can have them structured as
setLayout(new GridLayout(2,2));


0
 
aozarovCommented:
GridLayout shoudl strech your components, so I think your problem is actually the FlowLayout of each Panel
which can be replaced with GridLayout as well (if you want to fill the space).
You might want to consider Dave, GridBagLayout suggestion, for a much more powerfull positioning support.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now