|
-
Feb 1st, 2005, 04:36 PM
#1
Thread Starter
Frenzied Member
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.
-
Feb 1st, 2005, 06:07 PM
#2
Thread Starter
Frenzied Member
Re: add space between jtextareas
Never mind. Gridlayout has veritical and horizontal space as some of it's parameters.
-
Feb 1st, 2005, 10:30 PM
#3
Dazed Member
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 "));
-
Feb 2nd, 2005, 04:38 AM
#4
Addicted Member
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?!
-
Feb 2nd, 2005, 06:07 AM
#5
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|