Results 1 to 5 of 5

Thread: add space between jtextareas

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Resolved add space between jtextareas

    I have an array of textareas and they are all clumped together. I was wondering if anyone knew a way to put spaces in between them. Now, I have to use the gridlayout, and I had to use Jtextareas because I don't know how to set multiline on the textfields. Here is the code:

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class CheckerBoard extends JFrame
    {
    JButton btnGo;
    JTextArea[] txtAreas;
    JTextField[] txtFields;
    
    public CheckerBoard()
    {
    JPanel upperPanel= new JPanel();
    upperPanel.setLayout(new GridLayout(4,4));
    txtAreas = new JTextArea[16];
    for (int i=0; i<txtAreas.length; i++)
    {
    txtAreas = new JTextArea(i+"",4,4);
    upperPanel.add(txtAreas);
    }
    
    JPanel inputRow = new JPanel();
    inputRow.setLayout(new GridLayout(1,3));
    txtFields = new JTextField[3];
    for (int c=0; c<txtFields.length; c++)
    {
    txtFields[c] = new JTextField(8);
    inputRow.add(txtFields[c]);
    }
    
    JPanel labelRow = new JPanel();
    labelRow.setLayout(new GridLayout(1,3));
    JLabel[] lbl = new JLabel[3];
    for (int a=0; a<lbl.length; a++)
    {
    lbl[a] = new JLabel("");
    labelRow.add(lbl[a]);
    }
    lbl[0].setText(" Start ");
    lbl[1].setText(" Stop ");
    lbl[2].setText(" Step ");
    
    
    JPanel bRow = new JPanel();
    btnGo = new JButton(" GO! ");
    bRow.add(btnGo);
    
    Container pane = getContentPane();
    pane.setLayout(new FlowLayout());
    pane.add(upperPanel);
    pane.add(inputRow);
    pane.add(labelRow);
    pane.add(bRow);
    
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setContentPane(pane);
    setSize(370,400);
    setTitle("CheckerBoard");
    setVisible(true);
    }
    
    public static void main(String[] args)
    {
    CheckerBoard cb = new CheckerBoard();
    }
    }



    <Moderator added green checkmark on the first thread>
    Last edited by NoteMe; Feb 17th, 2005 at 07:10 AM.

  2. #2

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: add space between jtextareas

    Never mind. Gridlayout has veritical and horizontal space as some of it's parameters.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: add space between jtextareas

    Usually when i need to space things out i use the invisible separator components that are found in the Box class.
    Code:
     // imports......... 
     Containter row1 = new JPanel(); 
     row1.setLayoutManager(new BoxLayout(BoxLayout.X_AXIS));
     row1.add(new JLabel("Label 1)); 
     row1.add(Box.createHorizontalStrut(5)); 
     row1.add(new JLabel("Label "));

  4. #4
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Re: add space between jtextareas

    you could always add an empty border to the component your adding therefore forcing white space without messing around with the layout manager?!

  5. #5

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: add space between jtextareas

    GridLayout has some kind of space thing in it's constructor that's pretty cool:

    Code:
    Container pane = getContentPane();
    pane.setLayout(new GridLayout(4,4,8,8));

Posting Permissions

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



Click Here to Expand Forum to Full Width