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>




Reply With Quote