Results 1 to 3 of 3
  1. #1
    Javasubbu is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Alignment and Text Field size problem of Frame.

    Hi,

    The program given below does give me output but it is right justified. How can I make it centered? And more over, if I setSize for frame it the JTextField becomes too big. How can I limit the size of JTextField.?

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    class frametest{
    public static void main(String args[]){
    JFrame f = new JFrame("Customer details");
    JPanel p = new JPanel();
    
    GroupLayout layout = new GroupLayout(p);
    p.setLayout(layout);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel name = new JLabel("Enter the name of the customer");
    JLabel add = new JLabel("Enter the address of the customer");
    JTextField tname = new JTextField(15);
    JTextField tadd = new JTextField(15);
    
    
    GroupLayout.SequentialGroup s1 = layout.createSequentialGroup();
    GroupLayout.ParallelGroup t2b1 = layout.createParallelGroup();
    t2b1.addComponent(name);
    t2b1.addComponent(add);
    s1.addGroup(t2b1);
    GroupLayout.ParallelGroup t2b2 = layout.createParallelGroup();
    t2b2.addComponent(tname);
    t2b2.addComponent(tadd);
    s1.addGroup(t2b1);
    s1.addGroup(t2b2);
    
    GroupLayout.SequentialGroup s2 = layout.createSequentialGroup();
    GroupLayout.ParallelGroup t2b3 = layout.createParallelGroup();
    t2b3.addComponent(name);
    t2b3.addComponent(tname);
    GroupLayout.ParallelGroup t2b4 = layout.createParallelGroup();
    t2b4.addComponent(add);
    t2b4.addComponent(tadd);
    s2.addGroup(t2b3);
    s2.addGroup(t2b4);
    
    layout.setHorizontalGroup(s1);
    layout.setVerticalGroup(s2);
    f.add(p);
    f.pack();
    
    f.setVisible(true);
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Alignment and Text Field size problem of Frame.

    Use a layout or combination of layouts that you can code and understand. GroupLayout is meant for use by visual designers, and a visual designer is categorically not a beginner's tool.

    Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Javasubbu is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Alignment and Text Field size problem of Frame.

    Goodie, Thanks for replying! Will do so...

Similar Threads

  1. Replies: 4
    Last Post: 01-18-2011, 08:22 AM
  2. Problem Reading in data from Text Field
    By markious in forum AWT / Swing
    Replies: 2
    Last Post: 02-12-2010, 02:29 AM
  3. text area size problem
    By collin389 in forum AWT / Swing
    Replies: 7
    Last Post: 11-09-2009, 02:15 AM
  4. Problem with text field patern
    By Prashant.surwade in forum Advanced Java
    Replies: 1
    Last Post: 09-05-2009, 02:45 AM
  5. Setting frame size to the size of an image
    By Yoruichi in forum AWT / Swing
    Replies: 5
    Last Post: 04-22-2009, 04:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •