Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Layout components...help please

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Layout components...help please

    Hi

    I having a problem with thsi code:

    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
     
    import javax.swing.ButtonGroup;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.ListSelectionModel;
     
     
     
    public class teste extends JApplet implements ActionListener
    {
     private JTextField t1;
     private JLabel l1, l2, l3, l4;
     private JPanel p1,p2,p3,p4, p5;
     private JRadioButton rb1, rb2;
     private JCheckBox cb1,cb2,cb3;
     private ButtonGroup grupo;
     private JTextArea ta1;
     private JButton bt1, bt2;
     
     
     public void init()
     {
      setLayout(new GridLayout(5,2));
      //1º linha
      p1 = new JPanel();
      p1.setLayout(new GridLayout(1,2));
      l1 = new JLabel("Nome");
      t1 = new JTextField(10);
      p1.add(l1);
      p1.add(t1);
     
      //2ª linha
      p2 = new JPanel();
      p2.setLayout(new GridLayout(1,2));
      l2 = new JLabel("Género");
      rb1 = new JRadioButton("Maculino");
      rb1.addActionListener(this);
      rb2 = new JRadioButton("Feminino");
      rb2.addActionListener(this);
      p2.add(l2);
      p2.add(rb1);
      p2.add(rb2);
      ButtonGroup grupo=new ButtonGroup();
      grupo.add(rb1);
      grupo.add(rb2);
     
      //3ª linha
      p3 = new JPanel();
      p3.setLayout(new GridLayout(1,2));
      l3 = new JLabel("Passatempos");
      cb1 = new JCheckBox("Ler");
      cb2 = new JCheckBox("Jogar");
      cb3 = new JCheckBox("Viajar");
      p3.add(l3);
      p3.add(cb1);
      p3.add(cb2);
      p3.add(cb3);
     
      //4ª Linha
      p4 = new JPanel();
      p4.setLayout(new GridLayout(1,2));
      l4 = new JLabel("Morada");
      ta1 = new JTextArea(5,20);
      p4.add(l4);
      p4.add(ta1);
     
      //5ª linha
      p5 = new JPanel();
      p5.setLayout(new GridLayout(1,2));
      bt1 = new JButton("Limpar");
      bt1.addActionListener(this);
      bt2 = new JButton("Ver +");
      bt2.addActionListener(this);
      p5.add(bt1);
      p5.add(bt2);
     
      //Componentes na applet
      add(p1);
      add(p2);
      add(p3);
      add(p4);
      add(p5);
     }
     
     
     @Override
     public void actionPerformed(ActionEvent arg0) {
      // TODO Auto-generated method stub
     
     }
    }

    I want to have 5 rows and 2 columns and each cell has one component.


    any help to resolve this issue?


    regards


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Layout components...help please

    Erm... What exactly is your problem? Are you getting errors? Are things not aligning as you'd expect? Please be a little more specific.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Layout components...help please

    Hi

    Thanks for your reply.
    No there is no error, just the way they are aligning.
    I choosed GridLayout(1,2) to put 2 components (Label, Textfield) for example each row and one to old all of them.
    What i have is all components in strange positions, not the way i want (1,2).

    any help?

    thanks

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Layout components...help please

    Is there any way you could get a screenshot of what it looks like, and then post it here?
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  6. #6
    Junior Member
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Layout components...help please

    Hi

    Thanks....again

    The image is here:
    http://img864.imageshack.us/img864/5808/novaimagemx.png

    regards

  7. #7
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Layout components...help please

    I can't view that right now (school filter blocks the site). I'll try to remember to do it when I get home today. Sorry for the delay! In my absence, I highly suggest reading the page KevinWorkman linked you to, as well as this page about GridLayout.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Similar Threads

  1. Is there a layout for this?
    By gkffjcs in forum AWT / Java Swing
    Replies: 2
    Last Post: September 27th, 2011, 09:15 AM
  2. Replies: 1
    Last Post: April 14th, 2011, 07:50 AM
  3. Grid bag layout inside grid bag layout
    By kiddkoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2011, 08:07 AM
  4. Layout manager
    By kurt-hardy in forum AWT / Java Swing
    Replies: 3
    Last Post: January 19th, 2011, 10:25 AM
  5. How do you layout these components centered
    By robertbob in forum AWT / Java Swing
    Replies: 2
    Last Post: May 24th, 2010, 11:52 PM